How to make each MQTT Publih Message in Separate Packet?

im making an E-Ticketing system and i use MQTT V3.1.1 to allow user open the gate (Gate was make using Raspberry Pi 3 Model B+).

in this case, i want to load test the broker and raspberry with 10000 publish message and different topic for each message (topic range from bcn/bcn0000 - bcn/bcn00010000) with payload of unix nano timestamp in one time. the test was successful but when i try to capture the MQTT packets that goes into my Raspberry Pi during the test, it only capture less than 10000 (it should be 10000 packets right?) MQTT Publish message and im using MQTT QoS 0. the broker i'm using is Mosquitto installed in my VPS.

the captured packets (captured using TCPDUMP) has more than 10 MQTT Publish Message in one MQTT Packets. is this caused by nagle's algorithm? and how to make each message sent in the same time with separate packets for each publish message

Edit : serverside programming & logic using golang (paho.mqtt.golang) and raspberry using python (paho.mqtt.python) and i set set_tcp_nodelay on mosquitto.conf to true but no luck

stacked MQTT publish messages on one MQTT Packet list of captured packets on raspberry pi viewed on wireshark

Upvotes: 1

Views: 1473

Answers (2)

ImranRazaKhan
ImranRazaKhan

Reputation: 2297

Please use below line in python paho client to disable Nagle Algorithm, which will not send multiple messages in one packet/frame

client.connect("0.0.0.0", 1883, 60)  
client.socket().setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, True)

Upvotes: 2

linxingyang
linxingyang

Reputation: 31

the captured packets (captured using TCPDUMP) has more than 10 MQTT Publish Message in one MQTT Packets. is this caused by nagle's algorithm? and how to make each message sent in the same time with separate packets for each publish message

i set set_tcp_nodelay on mosquitto.conf to true but no luck

set_tcp_nodelay should work, but maybe send message in the same time so some message are binding together deliver to tcp/ip layer from application layer.

is there some method like flush() in (paho.mqtt.golang)?

or the most bad idea is, publish one message, close the connection and restart a new connection to send the next message. crazy...

and like @hardillb, i'm curious why you want send separate packets? according to the tcp/ip model, we don't care how message sending in the tcp/ip layer, we can receive correct message in application layer and that's enough.

Upvotes: 0

Related Questions