问题描述
我想对mosquitto进行压力测试,所以我创建了一些代码,如下所示
i want to make stress test on mosquitto, so i create some code as below
for (int i = 0; i < 800; i++) {
final int j = i;
Thread t = new Thread(new Runnable() {
@Override
public void run() {
System.out.println(j + " : ************");
try {
MqttClient client = new MqttClient("tcp://192.168.88.203", SERVER_CLIENTID_PREFIX + j);
client.connect();
MqttMessage message = new MqttMessage((j + ":me").getBytes());
message.setQos(2);
client.publish(TOPIC_PREFIX + j, message);
} catch (MqttSecurityException e) {
e.printStackTrace();
} catch (MqttException e) {
e.printStackTrace();
}
}
});
t.start();
}
但是,我遇到了一些错误,比如 EOFException
在运行期间和某些客户端断开连接。
我想知道有多少客户可以使用一台mosquitto服务器同时发布消息,我该如何进行压力测试。谢谢!
But, I got some errors like EOFException
during run and some client is disconnect.I want to know how many clients can publish messages at same time with one mosquitto server, and how can I make the stress test. Thanks!
详细例外是:
Connection lost (32109) - java.io.EOFException
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:162)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.io.EOFException
at java.io.DataInputStream.readByte(DataInputStream.java:250)
at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:51)
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:121)
... 1 more
我从mosquitto服务器找到了一些日志:
And I found some log from mosquitto server:
1383736170: Socket read error on client Server-82, disconnecting.
请帮助我,谢谢!
推荐答案
我使用类似上面的代码得到了完全相同的错误。我发现将QOS更改为0修复了问题。
I got this exact same error using code similar to above. I found that changing the QOS to 0 fixed the problem.
message.setQos(0);
再挖掘一下,我发现RabbitMQ的MQTT插件不支持QOS为2.
A bit more digging and I discovered that the MQTT plugin for RabbitMQ doesn't support a QOS of 2. http://www.rabbitmq.com/mqtt.html
这篇关于带有paho的java.io.EOFException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!