- MATLAB processing time: MATLAB might have additional processing overhead compared to Python, which could contribute to the higher latency. To address this, you can optimize your MATLAB code to reduce processing time or consider parallelizing certain tasks to improve efficiency.
- MATLAB event queue: MATLAB might be using an event-driven model for handling MQTT messages, which can introduce variability in the latency. Check if there is an event queue or buffer in MATLAB that could be causing the fluctuations. You can try to increase the event queue size or implement a more efficient event handling mechanism to reduce latency variations.
- Network conditions: Fluctuations in network conditions, such as network congestion or packet loss, can impact the latency of MQTT messages. Check your network setup and ensure that it is stable and reliable. You can also try monitoring the network traffic during the latency spikes to identify any potential issues.
- MQTT client configuration: Review the configuration options of the MQTT client in MATLAB. There might be settings related to message handling, buffering, or QoS (Quality of Service) that could affect the latency.
- MATLAB and MQTT library versions: Ensure that you are using the latest versions of MATLAB and the MQTT library. Sometimes, software updates can include performance improvements or bug fixes that could help reduce latency variations.
- Hardware limitations: Consider the hardware resources of your system, such as CPU and memory usage. If the system is under heavy load or if the hardware is not sufficient, it can contribute to latency fluctuations. Optimize your system resources and consider upgrading hardware if necessary.
High and Variable Latency in MQTT Communication Using the Industrial Communication Toolbox
10 次查看(过去 30 天)
显示 更早的评论
Hello, I'm using an MQTT client from the Industrial Communication Toolbox. I'm sending an input via Python to MATLAB over MQTT every 100ms. The latency between sending in Python and receiving in MATLAB averages about 60ms, but the latency fluctuates significantly. It seems like the latency keeps increasing until it reaches around 120ms delay, and then it drops back to 6ms. When I measure the latency in Python between sending and receiving, it's only 1ms.
I'm wondering why the latency is so high and variable in MATLAB. I need a consistent latency for my program, rather than such significant fluctuations. If anyone has any suggestions on how to address this issue, I would be very grateful.
0 个评论
回答(2 个)
Sivapriya Srinivasan
2023-9-5
Hello ,
Here are a few potential causes and suggestions to address the issue:
It is recommended to perform profiling and benchmarking tests on your MATLAB code to identify any potential bottlenecks or areas for optimization. Additionally, consult the documentation : MQTT API - MATLAB & Simulink (mathworks.com)
Hope this helps!
0 个评论
Ernst van der Pols
2024-1-10
Hello Tobias,
I have referred to your question in my answer to my own question rearding MQTT v5 support in MATLAB. I am just starting with MQTT in MATLAB, so I cannot confirm your issues (yet) or confirm that I have a solution, but I (thanks to Gennaro Notomista) provide the steps to build your own wrapper around the Paho MQTT Java client.
In case of serious issues it might be the only solution to tweak the Java client, or replace it with other alternatives.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!