Skip to content

Instantly share code, notes, and snippets.

@ralight
Last active December 15, 2015 02:39
Show Gist options
  • Save ralight/5188913 to your computer and use it in GitHub Desktop.
Save ralight/5188913 to your computer and use it in GitHub Desktop.
Create 1000 mqtt clients (in 1000 threads) to test broker connections.
#!/usr/bin/python
import mosquitto
import time
def on_connect(mosq, obj, rc):
print("Connected: "+mosq._client_id)
def on_disconnect(mosq, obj, rc):
print("Disconnected: "+mosq._client_id + " ("+str(rc)+")")
for i in range(0, 1000):
mosq = mosquitto.Mosquitto()
mosq.on_connect = on_connect
mosq.on_disconnect = on_disconnect
mosq.connect("localhost", 1883, 60)
mosq.subscribe("$SYS/#", 0)
mosq.loop_start()
while True:
time.sleep(1)
#!/usr/bin/python
import time
import subprocess
for i in range(0, 1000):
client = subprocess.Popen(('mosquitto_sub', '-t', '$SYS/#', '-p', '1883', '-h', 'localhost'))
while True:
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment