Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
47598ca2
提交
47598ca2
authored
8 年前
作者:
Thomas Mueller Graf
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
MVStore: add feature to set the cache concurrency (benchmark)
上级
4ee7e5fe
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
77 行增加
和
0 行删除
+77
-0
TestBenchmark.java
h2/src/test/org/h2/test/store/TestBenchmark.java
+77
-0
没有找到文件。
h2/src/test/org/h2/test/store/TestBenchmark.java
浏览文件 @
47598ca2
...
@@ -9,10 +9,17 @@ import java.sql.Connection;
...
@@ -9,10 +9,17 @@ import java.sql.Connection;
import
java.sql.PreparedStatement
;
import
java.sql.PreparedStatement
;
import
java.sql.Statement
;
import
java.sql.Statement
;
import
java.util.Random
;
import
java.util.Random
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
org.h2.mvstore.MVMap
;
import
org.h2.mvstore.MVStore
;
import
org.h2.store.FileLister
;
import
org.h2.store.FileLister
;
import
org.h2.store.fs.FileUtils
;
import
org.h2.store.fs.FileUtils
;
import
org.h2.test.TestBase
;
import
org.h2.test.TestBase
;
import
org.h2.util.Profiler
;
import
org.h2.util.Task
;
/**
/**
* Tests performance and helps analyze bottlenecks.
* Tests performance and helps analyze bottlenecks.
...
@@ -30,6 +37,7 @@ public class TestBenchmark extends TestBase {
...
@@ -30,6 +37,7 @@ public class TestBenchmark extends TestBase {
@Override
@Override
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
testConcurrency
();
// TODO this test is currently disabled
// TODO this test is currently disabled
...
@@ -41,6 +49,75 @@ public class TestBenchmark extends TestBase {
...
@@ -41,6 +49,75 @@ public class TestBenchmark extends TestBase {
test
(
false
);
test
(
false
);
}
}
private
void
testConcurrency
()
throws
Exception
{
// String fileName = getBaseDir() + "/" + getTestName();
String
fileName
=
"nioMemFS:/"
+
getTestName
();
FileUtils
.
delete
(
fileName
);
MVStore
store
=
new
MVStore
.
Builder
().
cacheSize
(
16
).
fileName
(
fileName
).
open
();
MVMap
<
Integer
,
byte
[]>
map
=
store
.
openMap
(
"test"
);
byte
[]
data
=
new
byte
[
1024
];
int
count
=
1000000
;
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
map
.
put
(
i
,
data
);
}
store
.
close
();
for
(
int
concurrency
=
1024
;
concurrency
>
0
;
concurrency
/=
2
)
{
testConcurrency
(
fileName
,
concurrency
,
count
);
testConcurrency
(
fileName
,
concurrency
,
count
);
testConcurrency
(
fileName
,
concurrency
,
count
);
}
FileUtils
.
delete
(
fileName
);
}
private
void
testConcurrency
(
String
fileName
,
int
concurrency
,
final
int
count
)
throws
Exception
{
Thread
.
sleep
(
1000
);
final
MVStore
store
=
new
MVStore
.
Builder
().
cacheSize
(
256
).
cacheConcurrency
(
concurrency
).
fileName
(
fileName
).
open
();
int
threadCount
=
128
;
final
CountDownLatch
wait
=
new
CountDownLatch
(
1
);
final
AtomicInteger
counter
=
new
AtomicInteger
();
final
AtomicBoolean
stopped
=
new
AtomicBoolean
();
Task
[]
tasks
=
new
Task
[
threadCount
];
// Profiler prof = new Profiler().startCollecting();
for
(
int
i
=
0
;
i
<
threadCount
;
i
++)
{
final
int
x
=
i
;
Task
t
=
new
Task
()
{
@Override
public
void
call
()
throws
Exception
{
MVMap
<
Integer
,
byte
[]>
map
=
store
.
openMap
(
"test"
);
Random
random
=
new
Random
(
x
);
wait
.
await
();
while
(!
stopped
.
get
())
{
int
key
=
random
.
nextInt
(
count
);
byte
[]
data
=
map
.
get
(
key
);
if
(
data
.
length
>
1
)
{
counter
.
incrementAndGet
();
}
}
}
};
t
.
execute
(
"t"
+
i
);
tasks
[
i
]
=
t
;
}
wait
.
countDown
();
try
{
Thread
.
sleep
(
3000
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
stopped
.
set
(
true
);
for
(
Task
t
:
tasks
)
{
t
.
get
();
}
// System.out.println(prof.getTop(5));
String
msg
=
"concurrency "
+
concurrency
+
" threads "
+
threadCount
+
" requests: "
+
counter
;
System
.
out
.
println
(
msg
);
trace
(
msg
);
store
.
close
();
}
private
void
test
(
boolean
mvStore
)
throws
Exception
{
private
void
test
(
boolean
mvStore
)
throws
Exception
{
// testInsertSelect(mvStore);
// testInsertSelect(mvStore);
// testBinary(mvStore);
// testBinary(mvStore);
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论