MQTT unthreaded node type
I have started a new branch mqtt_unthreaded for the implementation of a new variant of the MQTT node type that does not use threaded network operation management. It avoids calling
mosquitto_loop_start/stop(..) to avoid the creation of a new thread for each MQTT VILLASnode client. Instead, a new loop function is added to the new node type for invoking
mosquitto_loop(...) and reconnecting to the broker if connection was lost.
This implies that it is the user's responsibility to invoke the loop method often enough to keep the connection up. This can be done by frequently calling
node_read/write(...) for the node type. Also most of the the callback functions required by mosquitto invoke the loop method to perform network operations.
Another difference to the original mqtt node type is that
node_start(...) returns upon completion of topic subscription for the client. That means receiving messages works after
node_start(...) has returned. This might not be the case in the original mqtt node type.
The unthreaded variant is expected to provide a better performance (latencies...) in cases where many VILLASnode MQTT clients are started on one host.
An idea to improve the stability of unthreaded mqtt node type is starting one thread for calling
mosquitto_loop(...) in the
node_type_start(...) method. This thread would invoke the mosquitto networking loop for each MQTT client that is created by the process. It could work based on a global list of VILLASnode mqtt clients.
Comments and further ideas are welcome!