Skip to content

Fixes for low performance HA servers #555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

Lurker00
Copy link

I'm yet to find time to update to HA Core 2025.x, and to incorporate your many changes to LocalTuya :(

Meanwhile, I ran many tests with low performance HA server, and, as the result, these are related fixes. I suggest to read commit by commit: they all should be understandable. Yes, I saw all the fixed misbehaviors in real life!

Yes, I saw successful connects after 4.5 seconds. But, regardless, making TIMEOUT_CONNECT (was 3) less than TIMEOUT_REPLY has not much sense: usually connect is even longer process.

I've changed HEARTBEAT_INTERVAL to 8.3 because 83 is a big enough prime number. Making periodic tasks with periods of prime numbers decrease the chance of "crowded" periodic events across the whole system.

Copy link
Owner

@xZetsubou xZetsubou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR as always <3.

@Lurker00
Copy link
Author

Lurker00 commented Feb 19, 2025

Just FYI, yesterday in my home a source of 2.4GHz interference appeared, leading to high packet loss via WiFi connections. The interference is not continuous: there are some seconds pulses every some minutes. I'm logging calculated delays, if they are big:

                delta = (time.monotonic() - start) - HEARTBEAT_INTERVAL
                if delta > (11-HEARTBEAT_INTERVAL):
                    self.info(f"Delta {delta} fails {fail_attempt}")
                delta = max(0, min(delta, HEARTBEAT_INTERVAL))

Here is extraction from my logs:

2025-02-19 11:52:08.701 INFO (MainThread) [custom_components.localtuya.core.pytuya] [bf5...wrf - ВС: Wired Zigbee gateway] Delta 5.743602296034805 fails 0
2025-02-19 11:52:08.721 INFO (MainThread) [custom_components.localtuya.core.pytuya] [bfa...hkb - Iot Fan Tower T1] Delta 8.280447005107998 fails 0
2025-02-19 11:52:08.723 INFO (MainThread) [custom_components.localtuya.core.pytuya] [bf1...una - К: BLE Шлюз GW003] Delta 6.5229466349584975 fails 0
2025-02-19 11:52:08.723 INFO (MainThread) [custom_components.localtuya.core.pytuya] [bf8...tpj - ГЛ4: LED BULB W5K] Delta 8.24631225997582 fails 0
2025-02-19 11:52:08.791 INFO (MainThread) [custom_components.localtuya.core.pytuya] [bf7...dvp - ГЛ0: умная лампочка] Delta 6.28164764009416 fails 0
2025-02-19 11:52:08.792 INFO (MainThread) [custom_components.localtuya.core.pytuya] [bfc...hfr - ГЛ3: LED BULB W5K] Delta 6.590917618991806 fails 0
2025-02-19 11:52:08.792 INFO (MainThread) [custom_components.localtuya.core.pytuya] [bf0...sti - ГЛ2: LED BULB W5K] Delta 6.475475615053437 fails 0
2025-02-19 11:52:08.793 INFO (MainThread) [custom_components.localtuya.core.pytuya] [bfc...9vr - ГЛ1: LED BULB W5K] Delta 3.2039450939511873 fails 0
2025-02-19 11:52:09.385 INFO (MainThread) [custom_components.localtuya.core.pytuya] [bf1...sa9 - ВС: Питание HA] Delta 4.636976286931894 fails 0
2025-02-19 11:52:09.386 INFO (MainThread) [custom_components.localtuya.core.pytuya] [bf0...vcr - ВС: Питание шлюза Zigbee] Delta 4.948057062970474 fails 0
2025-02-19 11:52:09.387 INFO (MainThread) [custom_components.localtuya.core.pytuya] [bfd...ce8 - ВС: Питание HMG-01] Delta 5.449782188097014 fails 0

"fails 0" means no timeout waiting for a response, even when the delay > 5 seconds. But, if it was not the introduced sleep time correction, some devices might close connections as not active. Now all work just fine!

@Lurker00
Copy link
Author

For me, it looks like finished.

@xZetsubou xZetsubou merged commit 4cb04c3 into xZetsubou:master Feb 21, 2025
5 checks passed
@Lurker00 Lurker00 deleted the fixes_for_low_performance_ha_server branch February 21, 2025 07:36
xZetsubou pushed a commit that referenced this pull request Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants