Skip to content

ruby-mqtt 2x slower than paho-mqtt #115

@rgaufman

Description

@rgaufman

Hi there,

I'm comparing different ruby mqtt clients, I have this code:

client = MQTT::Client.new(username: 'testuser', password: 'testpasswd', client_id: "client_#{rand(1..1_000_000)}", host: '127.0.0.1', )
client.connect()

count = 0
loop do
  count += 1
  i = rand(1..10)

  topic = "to/timebox#{i}/cameras"
  msg = "message #{count} #{Time.now} for timebox#{i}"
  client.publish(topic, msg, true, 1)
end

Here is a version using paho-mqtt

$client = PahoMqtt::Client.new(username: 'testuser', password: 'testpasswd', client_id: "client_#{rand(1..1_000_000)}")
$client.connect('127.0.0.1', 1883)

$count = 0
def send_message
  $count += 1
  i = rand(1..$total)

  topic = "to/timebox#{i}/cameras"
  msg = "message #{$count} #{Time.now} for timebox#{i}"
  $client.publish(topic, msg, true, 1)
end

$client.on_puback { send_message } # QOS1
send_message
loop { sleep 1 } # to keep process running

I used pv to calculate how many messages are being received per second and I'm getting:

  • ruby-mqtt: 92 / sec
  • paho-mqtt: 180 /sec

I prefer the syntax of ruby-mqtt and it appears to be better maintained, but any ideas why ruby-mqtt is nearly 2x slower?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions