Latency reduction / increase performance #6892
Replies: 11 comments 24 replies
-
Hi, thx a lot for this feedback, I'm using docker for simple management of several things xx2mqtt. I have latency issue with buttons, sometime it's short, sometimes long not everytime the same latency. |
Beta Was this translation helpful? Give feedback.
-
Currently running HA and Zigbee2mqtt Docker containers on Debian 10, and HA automations related to Zigbee button presses are instantaneous... what sort of latency were you noticing before making these changes? |
Beta Was this translation helpful? Give feedback.
-
Stopped reading ... |
Beta Was this translation helpful? Give feedback.
-
Why are you so sure that docker or actually any software is causing your latency problems? Perhaps it's your coordinator, network. I'm not questioning that steps you took helped but maybe Docker and underlying OS isn't a root of your problem? |
Beta Was this translation helpful? Give feedback.
-
What kind of coordinator do you have all ? I have slaesh’s cc2652rb with lastest firmware in zigbee 3.0. |
Beta Was this translation helpful? Give feedback.
-
Hi. I'm using Aqara wireless wall switches + automations based on events form them. I wonder if there is a way to "disable" double clicks to make them "not wait" for second click. (in most cases i'm using only one click and double click). |
Beta Was this translation helpful? Give feedback.
-
I have a fairly complex setup, including:
I'd hate to follow the actual round trip of pushing a button - even if you ignore abstractions like virtualisation of networking and docker, it's probably at least 12+ hops from button push to lights on :) If I understand my logs correctly, the delay between pushing a button and a light coming on (or at least z2m reporting it is on), is 300ms
This is also using a CC2501, the slowest of the slow zigbee sticks, and using the old homeassistant_legacy_triggers, which generate a ton of noise and mqtt traffic. I would think 300ms is fast enough to be considered instant - it can't out perform a physical light switch, as that operates at basically the speed of light. |
Beta Was this translation helpful? Give feedback.
-
Hi everyone, Although I'm a huge fan of docker, I must say that I had similar problems (see #7108) Latency seems to be dissapeared immediatly.... Don't know if this due to docker architecture, or due to the implementation of mqtt-broker in HA-addon.... kind regards, |
Beta Was this translation helpful? Give feedback.
-
I have some xiaomi buttons that control smart lamps(wifi). Z2M logs that initial button press instantly so I know the issue is not there. So is this an issue with the MQTT broker? Anyone knows if they changed something the last few months that would cause this? |
Beta Was this translation helpful? Give feedback.
-
One of the best latency reductions you can do..
|
Beta Was this translation helpful? Give feedback.
-
Hi, I have a similar issue. Instead of or in addition to the mqtt message, I would like to react to an action with a rest/webhook call to avoid mqtt latency. For me, a relay (non zigbee) should be started when a key is pressed and stopped when it is released, and you can imagine that the detour via mqtt means latency. Does anyone have any ideas or tips? I would also consider self-customized legacy solutions. |
Beta Was this translation helpful? Give feedback.
-
Hi. Probably all of you are using Z2M in combination with some automation SW like HA / AppDaemon / NodeRed. Possibly some of you have some automations like "when button is pressed, then toggle a light".
I am one of such users and recently I was working on how latency between button press and the light status change can be minimalized. I want to share with you my findings and ask you, if you can propose something more or additional areas, where I can take a look.
So lets start with my findings:
Get rid of docker, if you are using it
Using docker adds additional delay in processing and adds a lot of new threads, that are needed to be managed by the task scheduler. That's of course introduce delay in processing. Use native installation methods to mitigate that problem.
EDIT
Problem is mainly with IO latency, creating new threads and context switching. Overall performance is not affected, but in terms of latency / reaction time there is a problem. References:
[1] https://www.researchgate.net/publication/341483813_Performance_Evaluation_of_Container_Runtimes
[2] https://www.phoronix.com/scan.php?page=news_item&px=AppArmor-Linux-5.5-72-Tests&fbclid=IwAR3u3nyP7B6XN4DgvPyD1Zrjw4oAbQfye5DRO95R1m6glgQ9_9EBAfdVDW4
[3] https://unix.stackexchange.com/questions/73515/does-apparmor-decrease-the-system-performance
Using Real time kernel
I have found out, that using the RT kernel like https://packages.debian.org/pl/linux-image-rt-amd64 can improve overall response time for serial / network events.
Use Round-robin scheduling policy
For mqtt broker, automation SW and Z2M use RR scheduling policy. In combination with RT kernel it will give those processes real time capabilities. Info https://man7.org/linux/man-pages/man7/sched.7.html
You can ensure, that RR scheduling policy is enforced by adding scheduling policy to systemd configuration file, for example:
Use dedicated automation SW
Using HA for automations is simple, but HA is quite big and automations are relatively slow. Using for example AppDaemon with MQTT addon gives a performance boost. Also thanks to that, you can put only automation SW into RR scheduling policy, leaving HA with default one.
Set "latency-performance" profile
I'm using "tuned" daemon to do that. See https://computingforgeeks.com/optimize-linux-system-performance-with-tuned-adm/ for more info.
Tune Z2M settings
It is needed to disable functions, that are not needed and disable some attributes from publishing.
General ones:
Per button/switch:
Other things
And that's all, what I found. I will be glad, if you can share your opinion and maybe add something to this topic.
Beta Was this translation helpful? Give feedback.
All reactions