Titel: High CPU usage (~60%) with v4.70.0 – fixed by downgrading to v4.66.8

I found the issue! :tada:

The Nuki integration was subscribing to the wildcard MQTT topic homeassistant/# on startup, even when the Nuki integration wasn’t being used :sweat_smile:

On top of that, the handling on the Nuki side was quite heavy for each Home Assistant discovery message, so it was consuming CPU for no reason.

What I changed:

  1. Only subscribe during a Nuki scan, and automatically stop listening after a 1-minute timeout
  2. Optimize the MQTT handler by returning early if the discovered device is not a Nuki device

@ProtZ Could you take a look at this PR to make sure I didn’t break anything in the Nuki integration?

If needed, I’ve built a Docker image for testing:

gladysassistant/gladys:fix-nuki-home-assistant-wildcard-listen 
3 Likes

Hi @Pierre-Gilles,

I tested the fix image gladysassistant/gladys:fix-nuki-home-assistant-wildcard-listen but unfortunately the CPU usage is still at ~60-70%.

No NotFoundError in the logs anymore (the retained messages race condition seems resolved), but the high CPU persists.

I also noticed that the LAN Manager presence scanner keeps calling ip neigh show even when set to « disabled » in the UI — but that’s likely not the main cause since the call frequency is low.

Any further ideas what could be causing constant high CPU at only ~0.8 msg/s MQTT throughput?

Ah, too bad :grinning_face_with_smiling_eyes:

At least we managed to fix a bug in the Nuki integration along the way!

The v4.67.0 release only includes three changes:

  • Nuki integration
  • Gladys Plus backup improvement
  • HAP dependency upgrade

To rule out any issue related to the HomeKit dependency update, could you try disabling the HomeKit integration entirely and then restarting Gladys?

You can do this in Settings → Services, by toggling off the Apple HomeKit service, then restarting Gladys.

This will help us confirm whether the issue is related to the HAP upgrade :slightly_smiling_face:

Thanks!

That’s it! When I disable Apple HomeKit in dashboard/settings/service, and restart the gladys container (the fix_nuki one AND latest, as of now, v4.71.0), CPU time goes way down, container cpu 0.3%
I do have apple devices, but i don’t run Apple home Kit devices anyway so FOR ME the problem is solved.

I assume this leaves you to figure out the cause for your other users. If I can provide sth that could help you, I’ll glady do so.

Again THANKS for all your work. It’s amazing.

4 Likes

Hi, I’m glad you were able to resolve your issue. If it’s related to the HomeKit integration, I’ll look into it. I’m pretty sure it’s an issue related to mdns, I’ve already mentioned it here: Installer Gladys sur NAS Qnap - #13 par bertrandda. The latest version of the dependency we’re using makes quite a few changes to it, and it seems to be causing issues with Docker.

I couldn’t reproduce issue on my Mac, but I’ve picked up a Linux PC to investigate. I am on it!

Great! Glad we were able to identify the main issue :grinning_face_with_smiling_eyes:

I’ll release the Nuki fix once I get confirmation from @ProtZ that everything is still working as expected.

@bertrandda, feel free to reach out if you need any help :+1:

Sorry I didn’t realize it could be a problem. Your PR is fine thx and a nice way to do for further mqtt scanning. I would like to add another correction in the PR, but I do not know how to do that.

I just realize that ‘device.get’ is not taking ‘service_id’ as parameter, it has to be ‘device.get({ service: ‹ nuki ›, });’ in nuki.mqtt.connect.js and nuki.mqtt.disconnect.js

Fixed in : Nuki: Should not process all homeassistant discovery messages by Pierre-Gilles · Pull Request #2502 · GladysAssistant/Gladys · GitHub

1 Like

I’ve tried everything, but I couldn’t reproduce what’s causing the CPU spike. I’ve tried to add a select on the Homekit integration configuration page to change the mDNS (which is what Homebridge does). If as I suspect, it’s an mDNS issue, that should do the trick.

A Docker image is available: bertrandda/gladys:homekit-mdns. Normally, the default is CIAO. @bamboleate could you please test each available mDNS and check the CPU usage? Once the configuration has been saved, you’ll need to wait a few seconds for the service to reload.

@bertrandda I noticed there’s a new version of @homebridge/hap-nodejs. Have you tried upgrading to the latest release?

Another idea: @bamboleate’s MQTT devices send roughly 1 message per second. Have you tried simulating a similar load by publishing MQTT messages at that rate to your instance? It could help confirm whether the HomeKit listener (which reacts to all state changes) has become too heavy and is causing the CPU spike.

Just merged the Nuki fix on master!

Great, thanks!

1 Like

Sooooo, I finally had the time to fiddle a little with the container bertrandda/gladys:homekit-mdns, and here is what I found

  • CPU % goes up immediately, when I start Apple homeKit Service/I click on the button in dashboard/settings/service
    initially it was set to CIAO
  • Set to AVAHI, I had a feeling of even a slight increase in CPU % compared to CIAO, but that could be me
  • Set to BONJOUR CPU% went down to normal values!!!
  • Set to RESOLVED the CPU% was up like the other three

Mind you, since I tinkered with networking, a server and Pis and stuff, I like my apple devices to be visible and not some kind of obscurely hidden by any “service” apple provides, so I tried to disable all that, and that maybe is a cause of this issue? Wouldn’t have believed it, but here we are…

I have disabled Apple’s ‹ Limit Tracking › option on my devices (which rotates IPs/MAC addresses), and my DNS runs on PiHole. Not sure if that’s related, but it might explain why BONJOUR works best in my setup. Currently running with BONJOUR and CPU is stable.

Hope this helps

EDIT: I forgot to mention that with the container bertrandda/gladys:homekit-mdns, CPU% went down immediately when I disable Apple Home Kit in dashboard/settings/service, while it stays up until I reload the container when it’s gladysassistant/gladys:latest, could be relevant to you as well

2 Likes

Thank you so much @bamboleate it’s exactly what I need to know.

I am going to set Bonjour as default mDNS. It was the legacy advertiser which was used with beta version of library.
We can see here mDNS Options · homebridge/homebridge Wiki · GitHub that for docker, avahi is recommended but need more configuration in docker, not sure that migration is possible for all existing Gladys instances. Bonjour advertiser should work for all configurations and if users want to optimize their configuration they can.

Yes, I added a correct stop function in this image that stop Homekit integration immediately, thank’s, you just confirmed that it works!

Yes the new version is in bertrandda/gladys:homekit-mdns image

2 Likes

Good news, all the fixes are live in Gladys Assistant 4.72: