7

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();
    }

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!

The detail exception is :

    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

And I found some log from mosquitto server:

1383736170: Socket read error on client Server-82, disconnecting.

Please help me, thanks!

ralight
  • 11,033
  • 3
  • 49
  • 59
tom
  • 71
  • 1
  • 1
  • 3
  • Can you post the exact exception? Sounds like the socket was closed. Can you try with a higher MQTT keepAlive value? I suspect that under this high load the Paho client doesn't manage to send pings properly. – Dominik Obermaier Nov 06 '13 at 18:20
  • thanks for your answer, i have append detail exception. What about the "keepAlive" value which you mention. i can not found it in mosquitto.conf , i only found "keepalive_interval" , is it right? thanks again – tom Nov 07 '13 at 06:25
  • 1
    32109 is the error code for "Connection Lost" on the client side. That means the socket was closed unexpectedly. If you want a higher keepAlive, you have to pass a MqttConnectOptions object to your connect() method with the defined keepAlive. If that doesn't help, I suspect that perhaps you are reaching a limit on the server side. Did you try with other brokers like HiveMQ or RabbitMQ? – Dominik Obermaier Nov 07 '13 at 12:53
  • Thank you , i modify my code as :client = new MqttClient("tcp://192.168.88.203", "Server-" + j); MqttConnectOptions connOpt = new MqttConnectOptions(); connOpt.setConnectionTimeout(60 * 10); connOpt.setKeepAliveInterval(60 * 5); – tom Nov 11 '13 at 07:39
  • but ,it can not make a good effection. I found if i don't publish message, the mosquitto server could accept 800 client connetion, but when i publish message, the '32109' error will be shown. I have no idea about this, sigh.... – tom Nov 11 '13 at 07:49
  • hi, when i run this run on linux os, it can work well, so pleasure, thank you for your answer – tom Nov 12 '13 at 08:34

7 Answers7

12

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);

[Edit] 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

Aidan
  • 1,550
  • 1
  • 13
  • 20
3

My issue resulted from the clientId being the same for the publisher/subscriber. Was getting errors with Persistence datastore already being in use as well.

mastash3ff
  • 312
  • 2
  • 8
2

client id is the problem, generating a random test

MqttClient.generateClientId ();
  • In my case after adding MqttClient.generateClientId(),Frequency of occurring this issue got reduced. If I set keepalive as 20 seconds,im not at all getting EOF exception. Any idea on this? – kavie Oct 13 '20 at 04:40
1

In my case this was because I was accidentally using a tcp://... URL instead of ssl://... and the server was configured not to allow insecure connections.

I also had to do as @Aidan said and reduce the QoS from 2 to 1.

Edit: I'm not 100% sure, but I think the server I'm using is RabbitMQ, and that assigns a non-standard meaning to the QoS values. It's probably a more sensible meaning to be honest:

Transient (QoS0) subscription use non-durable, auto-delete queues that will be deleted when the client disconnects.

Durable (QoS1) subscriptions use durable queues. Whether the queues are auto-deleted is controlled by the client's clean session flag. Clients with clean sessions use auto-deleted queues, others use non-auto-deleted ones.

Timmmm
  • 88,195
  • 71
  • 364
  • 509
0

There's a 1024 files/sockets limit in linux but you can upset it,ulimit -n 4096 see: mqtt mosquitto linux connection limit

Community
  • 1
  • 1
Teixi
  • 1,077
  • 8
  • 21
0

Sometimes it happen when you will try to send large data set. Try to decrease dataset size. It solved problem in my case.

Md Samiul Alim Sakib
  • 1,114
  • 12
  • 15
0

The solution is add MqttClient.generateClientId

MemoryPersistence persistence = new MemoryPersistence()
MqttClient client = new MqttClient("tcp://192.168.88.203",MqttClient.generateClientId(),persistence); 
client.connect();

or

MqttClient client = new MqttClient("tcp://192.168.88.203", MqttClient.generateClientId+SERVER_CLIENTID_PREFIX)

The identifier must be random. I had this problem in scala and that was my solution.