Skip to content

Slowness at reading many retained messages #9

Description

@leandronsp

Hey!

I'm around an issue which I'm not sure if it's related how I use the lib or something else on its internals.
By trying the following process:

@mqtt_client = PahoMqtt::Client.new(
  client_id: client_id,             
  username: username,               
  password: password                
)

@mqtt_client.connect(
  host=@mqtt_host,   
  port=@mqtt_port,   
  keep_alive=60,     
  persistent=true    
)

@mqtt_client.subscribe(['v1/some_topic'], 1) 

@mqtt_client.on_message do |message|                                       
  # print the retained/received message
end

At first, it will print all retained messages on the broker, around ~80 on ours.
It takes 10 seconds to load all 80 retained messages, which it seems to be very slow on our requirements.

Then I changed to use the foreground alternative.

@mqtt_client.connect(
  host=@mqtt_host,   
  port=@mqtt_port,   
  keep_alive=60,     
  persistent=true ,
  blocking=true  
)

def foreground_mode                                     
  [:loop_read, :loop_write, :loop_misc].each do |method|
    Thread.new do                                       
      while @mqtt_client.connected? do                  
        @mqtt_client.send(method)                       
      end                                               
    end                                                 
  end                                                   
end                                                     

# will spawn a different Thread for each loop
foreground_mode

Even so, this solution is even worse, taking 40 seconds, and I think it's related to the GIL maybe.

In addition, I compared along with the paho.mqtt.python lib, which in turn takes just 1 second instead to load all 80 retained messages. I'd gently ask you guys for some clue, am I missing something, some tweak to be made, already an known issue?

Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions