Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
mica
mica-mqtt
提交
5e1010c0
mica-mqtt
项目概览
mica
/
mica-mqtt
通知
71
Star
1
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
mica-mqtt
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
5e1010c0
编写于
8月 17, 2021
作者:
浅梦2013
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
✨
优化压测工具
上级
0b538242
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
19 addition
and
19 deletion
+19
-19
mica-mqtt-example/src/main/java/net/dreamlu/iot/mqtt/benchmark/MqttBenchmark.java
...in/java/net/dreamlu/iot/mqtt/benchmark/MqttBenchmark.java
+19
-19
未找到文件。
mica-mqtt-example/src/main/java/net/dreamlu/iot/mqtt/benchmark/MqttBenchmark.java
浏览文件 @
5e1010c0
...
...
@@ -16,12 +16,10 @@
package
net.dreamlu.iot.mqtt.benchmark
;
import
net.dreamlu.iot.mqtt.codec.ByteBufferUtil
;
import
net.dreamlu.iot.mqtt.core.client.MqttClient
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
/**
* mqtt 压力测试
...
...
@@ -29,26 +27,28 @@ import java.util.concurrent.TimeUnit;
* @author L.cm
*/
public
class
MqttBenchmark
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
MqttBenchmark
.
class
);
public
static
void
main
(
String
[]
args
)
{
// 1. 模拟 1w 连接,在开发机(i5-7500 4核4线程 win10 MqttServer 6G)1万连连接很轻松。
// 注意: windows 上需要修改最大的 Tcp 连接数,不然超不过 2W。
int
clientCount
=
1_0000
;
long
beginTime
=
System
.
nanoTime
();
for
(
int
i
=
0
;
i
<
clientCount
;
i
++)
{
// 2. 初始化 mqtt 客户端
MqttClient
client
=
MqttClient
.
create
()
.
username
(
"admin"
)
.
password
(
"123456"
)
.
readBufferSize
(
512
)
.
connect
();
// 3. 订阅服务端消息
client
.
subQos0
(
"/#"
,
(
topic
,
payload
)
->
{
logger
.
info
(
topic
+
'\t'
+
ByteBufferUtil
.
toString
(
payload
));
});
int
connCount
=
1_0000
;
int
threadCount
=
1000
;
String
ip
=
"8.130.24.89"
;
ExecutorService
executor
=
Executors
.
newFixedThreadPool
(
threadCount
);
for
(
int
i
=
0
;
i
<
connCount
;
i
++)
{
int
num
=
i
;
executor
.
submit
(()
->
newClient
(
ip
,
num
));
}
System
.
err
.
println
(
"批量连接完成,耗时:"
+
TimeUnit
.
NANOSECONDS
.
toMillis
(
System
.
nanoTime
()
-
beginTime
));
}
private
static
void
newClient
(
String
ip
,
int
i
)
{
MqttClient
.
create
()
.
ip
(
ip
)
.
clientId
(
"MICA-MQTT-"
+
i
)
.
username
(
"admin"
)
.
password
(
"123456"
)
.
readBufferSize
(
512
)
.
connect
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录