[mqtt] Reuse connections #448

Open
opened 2025-05-09 23:30:53 +02:00 by blacklight · 0 comments
Owner

As of now integrations like zigbee.mqtt and zwave.mqtt that extend the MqttPlugin and do a lot of publish+subscribe cycles are subject to big reconnection overheads - the current implementation of mqtt.publish closes the client after the response has been received.

If I have to query the state of many devices on a Zigbee or Z-Wave network, this can mean dozens of reconnections in a short time span.

A better implementation should:

  1. Retain an MQTT connection open on the MqttPlugin level, on a <host>:<port> basis.

  2. Add new subscriptions to the existing connection when needed.

  3. Internally dispatch calls to on_message to the right subscription(s) on a topic basis.

  4. Close the connection only when the plugin is stopped or when the last topic is unsubscribed - and only after a given keepalive time.

As of now integrations like `zigbee.mqtt` and `zwave.mqtt` that extend the `MqttPlugin` and do a lot of publish+subscribe cycles are subject to big reconnection overheads - the current implementation of `mqtt.publish` closes the client after the response has been received. If I have to query the state of many devices on a Zigbee or Z-Wave network, this can mean dozens of reconnections in a short time span. A better implementation should: 1. Retain an MQTT connection open on the `MqttPlugin` level, on a `<host>:<port>` basis. 2. Add new subscriptions to the existing connection when needed. 3. Internally dispatch calls to `on_message` to the right subscription(s) on a topic basis. 4. Close the connection only when the plugin is stopped or when the last topic is unsubscribed - and only after a given `keepalive` time.
blacklight added this to the v1.4.0 milestone 2025-05-09 23:30:53 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
platypush/platypush#448
No description provided.