emqx / mqtt-jmeter

MQTT JMeter Plugin
https://www.emqx.com/en
Apache License 2.0
445 stars 194 forks source link

使用多线程无法分步执行。 #55

Closed god-pane closed 5 years ago

god-pane commented 5 years ago

image 如图,我把MQTT Connect放到setUp Thread Group, 其他2个线程里面放置了publish, 最后一个tearDown Thread Group 放置MQTT DisConnect, 实际运行结果,只有MQTT Connect成功,其余的都失败了

jinfahua commented 5 years ago

Add an 'MQTT Connect' sampler into the same thread group of pub/sub samplers, and add a 'one only control group' as parent of 'MQTT Connect' sampler.

image

god-pane commented 5 years ago

如果使用一个线程的话, pub和sub没有办法并行,比如我下端需要每隔一小时pub设备的基本信息,同时也要sub服务端给的消息做反馈,这样的场景能实现么?

jinfahua commented 5 years ago

You can add sub sampler with 'sample on - specified elapsed time (ms)', then a sub sampler will be generated with your specified time period, and the thread will not be blocked.

image

Regarding to your pub sampler, you can add an if controller, the controller will check the timestamp of last publish, and the condition is satisfied only with one hour is passed. You also need to add a post-processor to the pub sampler for recording the timestamp of publish - beanshell script is recommended.

god-pane commented 5 years ago

设备sub消息的时间是不定的,因为不知道服务端何时会有需求, 所以我想的是用一个线程, 一直监听

jinfahua commented 5 years ago

设备sub消息的时间是不定的,因为不知道服务端何时会有需求, 所以我想的是用一个线程, 一直监听

No problem. You could check the response of sub sampler. If no contents returned in the sampler, then the sub sampler result is empty.

god-pane commented 5 years ago

能上图 给个列子嘛? 谢谢!

god-pane commented 5 years ago

最重要的是我的sub不是一次行为, 是多次, 不是说我收到一次消息处理后就要把这个sub结束,我希望他一直存在。

jinfahua commented 5 years ago

image

In thread group: Loop Count - check Forever image

god-pane commented 5 years ago

image 这个地方可以有多个sub吗?

god-pane commented 5 years ago

image 当我写了两个sub以后,发现两个sub收到的消息会混乱, 这个能优化解决吗?

能支持多个sub?@jinfahua

god-pane commented 5 years ago

知道了