rabbitmq / rabbitmq-server

Open source RabbitMQ: core server and tier 1 (built-in) plugins
https://www.rabbitmq.com/
Other
12.28k stars 3.91k forks source link

Make it possible to control Nagle's algorithm (TCP_NODELAY) and related socket options for Web MQTT #12331

Closed razvanphp closed 1 month ago

razvanphp commented 1 month ago

Is your feature request related to a problem? Please describe.

We are trying to set a low latency mqtt server that is also accessed from the web browser. Because of those constraints, we have to use web-mqtt plugin. We noticed while tracking the time with Wireshark that there is a delay in ACK of the packets sent.

We studied the plugin source code and we understood that since this plugin is using Ranch and under the hood, so tcp_listen_options.nodelay do not apply for the socket creation; instead, this needs to be set via tcp_config

https://github.com/rabbitmq/rabbitmq-server/blob/c593d706cd0dab75b4df8114a38cb7d1c1d35a99/deps/rabbitmq_web_mqtt/src/rabbit_web_mqtt_app.erl#L102

https://github.com/rabbitmq/rabbitmq-server/blob/c593d706cd0dab75b4df8114a38cb7d1c1d35a99/deps/rabbitmq_web_mqtt/src/rabbit_web_mqtt_app.erl#L130

Describe the solution you'd like

To be able to set those options as well, similar to simple mqtt:

2024-09-18 12:19:12.573263+00:00 [error] <0.156.0> You've tried to set web_mqtt.tcp.nodelay, but there is no setting with that name.
2024-09-18 12:19:12.581506+00:00 [error] <0.156.0>   Did you mean one of these?
2024-09-18 12:19:13.077702+00:00 [error] <0.156.0>     web_mqtt.tcp.backlog
2024-09-18 12:19:13.077811+00:00 [error] <0.156.0>     web_mqtt.tcp.port
2024-09-18 12:19:13.077891+00:00 [error] <0.156.0>     web_mqtt.tcp.ip
2024-09-18 12:19:13.078737+00:00 [error] <0.156.0> You've tried to set web_mqtt.ssl.nodelay, but there is no setting with that name.
2024-09-18 12:19:13.078797+00:00 [error] <0.156.0>   Did you mean one of these?
2024-09-18 12:19:13.472279+00:00 [error] <0.156.0>     web_mqtt.ssl.depth
2024-09-18 12:19:13.472404+00:00 [error] <0.156.0>     web_mqtt.ssl.backlog
2024-09-18 12:19:13.472491+00:00 [error] <0.156.0>     web_mqtt.ssl.port
2024-09-18 12:19:13.474844+00:00 [error] <0.156.0> Error preparing configuration in phase transform_datatypes:
2024-09-18 12:19:13.474914+00:00 [error] <0.156.0>   - Conf file attempted to set unknown variable: web_mqtt.ssl.nodelay
2024-09-18 12:19:13.474980+00:00 [error] <0.156.0>   - Conf file attempted to set unknown variable: web_mqtt.tcp.nodelay

Describe alternatives you've considered

setting this in the advanced config format:

      [
        {rabbitmq_web_mqtt, [
          {tcp_config, [{port, 15675}, {nodelay, true}]}
        ]}
      ].

Additional context

Thank you in advance!

michaelklishin commented 1 month ago

This will have to wait until after 4.0.0 ships.

razvanphp commented 1 month ago

Thank you for considering this!

Do you know if setting it via the advanced config has any effect? Seems to be accepted.

$ rabbitmqctl environment
[...]
 {rabbitmq_web_mqtt,
     [{cowboy_opts,[]},
      {num_ssl_acceptors,10},
      {num_tcp_acceptors,10},
      {proxy_protocol,false},
      {ssl_config,
          [{cacertfile,"/opt/bitnami/rabbitmq/certs/ca_certificate.pem"},
           {keyfile,"/opt/bitnami/rabbitmq/certs/server_key.pem"},
           {certfile,"/opt/bitnami/rabbitmq/certs/server_certificate.pem"},
           {port,15676},
           {backlog,1024}]},
      {tcp_config,[{port,15675},{nodelay,true}]}]},
dcorbacho commented 1 month ago

It should, rabbitmq_web_mqtt picks that tcp_config and passes it to ranch

razvanphp commented 1 month ago

hmm, actually it seems that the default nodelay value in ranch is true...

https://ninenines.eu/docs/en/ranch/1.7/manual/ranch_tcp/

michaelklishin commented 1 month ago

@razvanphp setting rabbitmq_web_mqtt settings via advanced.config works just like for any other Erlang app (plugin) or key.

How to Inspect Effective Configuration has been a dedicated doc section for years.

"This seems accepted" means nothing for advanced.config, it does not have validation beyond what certain parts of RabbitMQ may explicitly verify on boot.

michaelklishin commented 1 month ago

I do not understand what's being asked here any more => this is discussion material.