Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
Rocketmq
提交
32881d46
R
Rocketmq
项目概览
s920243400
/
Rocketmq
与 Fork 源项目一致
Fork自
Apache RocketMQ / Rocketmq
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rocketmq
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
32881d46
编写于
1月 21, 2021
作者:
许
许晓东
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add the property of benchmark producer that specifies how many messages to send
上级
6af12592
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
59 addition
and
10 deletion
+59
-10
example/src/main/java/org/apache/rocketmq/example/benchmark/Producer.java
.../java/org/apache/rocketmq/example/benchmark/Producer.java
+59
-10
未找到文件。
example/src/main/java/org/apache/rocketmq/example/benchmark/Producer.java
浏览文件 @
32881d46
...
...
@@ -17,12 +17,14 @@
package
org.apache.rocketmq.example.benchmark
;
import
java.io.UnsupportedEncodingException
;
import
java.util.Arrays
;
import
java.util.LinkedList
;
import
java.util.Random
;
import
java.util.Timer
;
import
java.util.TimerTask
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.atomic.AtomicLong
;
import
org.apache.commons.cli.CommandLine
;
...
...
@@ -58,9 +60,10 @@ public class Producer {
final
int
tagCount
=
commandLine
.
hasOption
(
'l'
)
?
Integer
.
parseInt
(
commandLine
.
getOptionValue
(
'l'
))
:
0
;
final
boolean
msgTraceEnable
=
commandLine
.
hasOption
(
'm'
)
&&
Boolean
.
parseBoolean
(
commandLine
.
getOptionValue
(
'm'
));
final
boolean
aclEnable
=
commandLine
.
hasOption
(
'a'
)
&&
Boolean
.
parseBoolean
(
commandLine
.
getOptionValue
(
'a'
));
final
long
messageNum
=
commandLine
.
hasOption
(
'q'
)
?
Long
.
parseLong
(
commandLine
.
getOptionValue
(
'q'
))
:
0
;
System
.
out
.
printf
(
"topic: %s threadCount: %d messageSize: %d keyEnable: %s propertySize: %d tagCount: %d traceEnable: %s aclEnable: %s%n"
,
topic
,
threadCount
,
messageSize
,
keyEnable
,
propertySize
,
tagCount
,
msgTraceEnable
,
aclEnable
);
System
.
out
.
printf
(
"topic: %s threadCount: %d messageSize: %d keyEnable: %s propertySize: %d tagCount: %d traceEnable: %s aclEnable: %s
messageQuantity: %d
%n"
,
topic
,
threadCount
,
messageSize
,
keyEnable
,
propertySize
,
tagCount
,
msgTraceEnable
,
aclEnable
,
messageNum
);
final
InternalLogger
log
=
ClientLogger
.
getLog
();
...
...
@@ -72,6 +75,16 @@ public class Producer {
final
LinkedList
<
Long
[]>
snapshotList
=
new
LinkedList
<
Long
[]>();
final
long
[]
msgNums
=
new
long
[
threadCount
];
if
(
messageNum
>
0
)
{
Arrays
.
fill
(
msgNums
,
messageNum
/
threadCount
);
long
mod
=
messageNum
%
threadCount
;
if
(
mod
>
0
)
{
msgNums
[
0
]
+=
mod
;
}
}
timer
.
scheduleAtFixedRate
(
new
TimerTask
()
{
@Override
public
void
run
()
{
...
...
@@ -85,14 +98,7 @@ public class Producer {
timer
.
scheduleAtFixedRate
(
new
TimerTask
()
{
private
void
printStats
()
{
if
(
snapshotList
.
size
()
>=
10
)
{
Long
[]
begin
=
snapshotList
.
getFirst
();
Long
[]
end
=
snapshotList
.
getLast
();
final
long
sendTps
=
(
long
)
(((
end
[
3
]
-
begin
[
3
])
/
(
double
)
(
end
[
0
]
-
begin
[
0
]))
*
1000L
);
final
double
averageRT
=
(
end
[
5
]
-
begin
[
5
])
/
(
double
)
(
end
[
3
]
-
begin
[
3
]);
System
.
out
.
printf
(
"Current Time: %s Send TPS: %d Max RT(ms): %d Average RT(ms): %7.3f Send Failed: %d Response Failed: %d%n"
,
System
.
currentTimeMillis
(),
sendTps
,
statsBenchmark
.
getSendMessageMaxRT
().
get
(),
averageRT
,
end
[
2
],
end
[
4
]);
doPrintStats
(
snapshotList
,
statsBenchmark
,
false
);
}
}
...
...
@@ -120,9 +126,14 @@ public class Producer {
producer
.
start
();
for
(
int
i
=
0
;
i
<
threadCount
;
i
++)
{
final
long
msgNumLimit
=
msgNums
[
i
];
if
(
messageNum
>
0
&&
msgNumLimit
==
0
)
{
break
;
}
sendThreadPool
.
execute
(
new
Runnable
()
{
@Override
public
void
run
()
{
int
num
=
0
;
while
(
true
)
{
try
{
final
Message
msg
;
...
...
@@ -198,10 +209,27 @@ public class Producer {
}
catch
(
InterruptedException
ignored
)
{
}
}
if
(
messageNum
>
0
&&
++
num
>=
msgNumLimit
)
{
break
;
}
}
}
});
}
try
{
sendThreadPool
.
shutdown
();
sendThreadPool
.
awaitTermination
(
Long
.
MAX_VALUE
,
TimeUnit
.
DAYS
);
timer
.
cancel
();
if
(
snapshotList
.
size
()
>
1
)
{
doPrintStats
(
snapshotList
,
statsBenchmark
,
true
);
}
else
{
System
.
out
.
printf
(
"[Complete] Send Total: %d Send Failed: %d Response Failed: %d%n"
,
statsBenchmark
.
getSendRequestSuccessCount
().
get
()
+
statsBenchmark
.
getSendRequestFailedCount
().
get
(),
statsBenchmark
.
getSendRequestFailedCount
().
get
(),
statsBenchmark
.
getReceiveResponseFailedCount
().
get
());
}
producer
.
shutdown
();
}
catch
(
InterruptedException
ignored
)
{
}
}
public
static
Options
buildCommandlineOptions
(
final
Options
options
)
{
...
...
@@ -233,6 +261,10 @@ public class Producer {
opt
.
setRequired
(
false
);
options
.
addOption
(
opt
);
opt
=
new
Option
(
"q"
,
"messageQuantity"
,
true
,
"Send message quantity, Default: 0, running forever"
);
opt
.
setRequired
(
false
);
options
.
addOption
(
opt
);
return
options
;
}
...
...
@@ -249,6 +281,23 @@ public class Producer {
return
msg
;
}
private
static
void
doPrintStats
(
final
LinkedList
<
Long
[]>
snapshotList
,
final
StatsBenchmarkProducer
statsBenchmark
,
boolean
done
)
{
Long
[]
begin
=
snapshotList
.
getFirst
();
Long
[]
end
=
snapshotList
.
getLast
();
final
long
sendTps
=
(
long
)
(((
end
[
3
]
-
begin
[
3
])
/
(
double
)
(
end
[
0
]
-
begin
[
0
]))
*
1000L
);
final
double
averageRT
=
(
end
[
5
]
-
begin
[
5
])
/
(
double
)
(
end
[
3
]
-
begin
[
3
]);
if
(
done
)
{
System
.
out
.
printf
(
"[Complete] Send Total: %d Send TPS: %d Max RT(ms): %d Average RT(ms): %7.3f Send Failed: %d Response Failed: %d%n"
,
statsBenchmark
.
getSendRequestSuccessCount
().
get
()
+
statsBenchmark
.
getSendRequestFailedCount
().
get
(),
sendTps
,
statsBenchmark
.
getSendMessageMaxRT
().
get
(),
averageRT
,
end
[
2
],
end
[
4
]);
}
else
{
System
.
out
.
printf
(
"Current Time: %s Send TPS: %d Max RT(ms): %d Average RT(ms): %7.3f Send Failed: %d Response Failed: %d%n"
,
System
.
currentTimeMillis
(),
sendTps
,
statsBenchmark
.
getSendMessageMaxRT
().
get
(),
averageRT
,
end
[
2
],
end
[
4
]);
}
}
}
class
StatsBenchmarkProducer
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录