AlexxIT / XiaomiGateway3

Home Assistant custom component for control Xiaomi Multimode Gateway (aka Gateway 3), Xiaomi Multimode Gateway 2, Aqara Hub E1 on default firmwares over LAN
https://github.com/AlexxIT/Blog
MIT License
2.42k stars 340 forks source link

Xiaomi Multimode Gateway 2 high CPU load_avg #1420

Open will-huang9531 opened 1 month ago

will-huang9531 commented 1 month ago

After upgrading the Multimode Gateway 1 to Multimode Gateway 2, during a routine inspection, it was found that the CPU load_avg of Multimode Gateway 2 was abnormally high: 9.29|9.15|9.17|2/130|1796 (according to the document, this value should be less than 3). And this gateway has only 25 sub devices. However, this device did not show any unnormal operation and there were no error logs.

Multimode Gateway 2 Firmwares: 1.0.7_0021 (I have the key) Gateway3 version: v4.0.5 Home Assistant Core: 2023.12.3

PS: It's interesting that I have a Multimode Gateway 1 in another house, but its load is within the normal range.(2.84|2.73|2.74|1/102|29388)

AlexxIT commented 4 weeks ago

You can use telnet to enter gateway's shell and run top command to find out problem application.

will-huang9531 commented 4 weeks ago

You can use telnet to enter gateway's shell and run top command to find out problem application.

thx for reply This is what the top command displays. ‘mha_master --log-level 6 --background’ Do you have any ideas about it?

iShot_2024-08-14_17 15 20
AlexxIT commented 3 weeks ago

This is main gateway's application. I'll check my gateway when I have time.

will-huang9531 commented 3 weeks ago

This is main gateway's application. I'll check my gateway when I have time.

I appreciate! I asked several friends who have the same device, and this seems to be a common situation. If you have time to fix it, we would greatly appreciate it.

AlexxIT commented 3 weeks ago

Maybe it's default behaviour. Better to check situation when integration haven't make any changes with gateway after reboot. Only open telnet.

will-huang9531 commented 3 weeks ago

Maybe it's default behaviour. Better to check situation when integration haven't make any changes with gateway after reboot. Only open telnet.

Does this mean that I need to enter the gateway by telnet to use top command without starting the home assistant? That‘s a bit difficult for me to do that. However, I tried to enter Multimode Gateway 1 by telnet, and use the TOP command, but ‘mha_master --log-level 6 --background’ did not occur. Does this indicate that this is a unique issue of Multimode Gateway 2?

iShot_2024-08-17_15 21 48
AlexxIT commented 3 weeks ago

It can be unique issue only for model 2.

AlexxIT commented 1 week ago

This is my gateway:

firmware: 1.0.7_0021
model: lumi.gateway.mcn001

free_mem: 42060
load_avg: 8.16|8.38|8.48|1/134|867
uptime: 22d14h30m7s

mha_master - 0% load

Lesnao commented 6 days ago

图片

50%cpu too

version 1.0.3_0028

zalatnaicsongor commented 6 days ago

The issue is simple to fix: turn off z3 support in the openmiio_agent and make sure that mZ3GatewayHost_MQTT is never running. This is a bug in openmiio_agent that always tries to restart the mZ3GatewayHost_MQTT if the z3 integration is set up even if mZ3GatewayHost_MQTT cannot possibly start up due to an incompatible zigbee firmware version.

Remove the string "z3" from here: https://github.com/AlexxIT/XiaomiGateway3/blob/master/custom_components/xiaomi_gateway3/core/shell/const.py#L2

will-huang9531 commented 5 days ago

mZ3GatewayHost_MQTT

Thank you for your solution, but 'mZ3GatewayHost_MQTT' only consumes a small amount of CPU load ,and the ‘mha_master --log-level 6 --background’ consumes a lot of CPU load. Are you sure there is a correlation between them?

AlexxIT commented 5 days ago

I'm also don't see any correlation.

Previous gateway has similar bug. It was because integration restarts MQTT on public port. And sometime main app starts consume a lot of CPU after that. The solution was - restart this main app. I thought this gateway model not affected. mha_master is main app

zalatnaicsongor commented 5 days ago

ration restarts MQTT on public port. And sometime main app starts consume a lot of CPU after that. The solution was - restart this main app. I thought this gateway model not affected. mha_master is main app

Try it, mha_master is what goes haywire if the mZ3GatewayHost_MQTT is always restarting. Ever since I fixed this, there is no excessive CPU usage on my gateway.

will-huang9531 commented 5 days ago

ration restarts MQTT on public port. And sometime main app starts consume a lot of CPU after that. The solution was - restart this main app. I thought this gateway model not affected. mha_master is main app

Try it, mha_master is what goes haywire if the mZ3GatewayHost_MQTT is always restarting. Ever since I fixed this, there is no excessive CPU usage on my gateway.

If possible, could you please provide your Gateway model, Gateway firmware version, Gateway3 version, and the CPU load? I will try it when I have time.