Skip to content
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

Avoid executor jump to resolve ip addresses #103

Merged
merged 1 commit into from
Sep 17, 2021

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented Sep 17, 2021

Similar to #26

Avoids executor overload at statup with lots of esphome devices

2021-09-17 07:34:00 DEBUG (MainThread) [homeassistant.util.executor] Calling executor with function: <function getaddrinfo at 0x7f96b7915a60>, args: (192.168.107.189, 6053, 0, 0, 6, 0), kwargs: {}
2021-09-17 07:34:00 DEBUG (MainThread) [homeassistant.util.executor] Calling executor with function: <function getaddrinfo at 0x7f96b7915a60>, args: (192.168.107.248, 6053, 0, 0, 6, 0), kwargs: {}
2021-09-17 07:34:00 DEBUG (MainThread) [homeassistant.util.executor] Calling executor with function: <function getaddrinfo at 0x7f96b7915a60>, args: (192.168.107.234, 6053, 0, 0, 6, 0), kwargs: {}
2021-09-17 07:34:00 DEBUG (MainThread) [homeassistant.util.executor] Calling executor with function: <function getaddrinfo at 0x7f96b7915a60>, args: (192.168.107.206, 6053, 0, 0, 6, 0), kwargs: {}
2021-09-17 07:34:00 DEBUG (MainThread) [homeassistant.util.executor] Calling executor with function: <function getaddrinfo at 0x7f96b7915a60>, args: (192.168.107.220, 6053, 0, 0, 6, 0), kwargs: {}
2021-09-17 07:34:00 DEBUG (MainThread) [homeassistant.util.executor] Calling executor with function: <function getaddrinfo at 0x7f96b7915a60>, args: (192.168.107.61, 6053, 0, 0, 6, 0), kwargs: {}
2021-09-17 07:34:00 DEBUG (MainThread) [homeassistant.util.executor] Calling executor with function: <function getaddrinfo at 0x7f96b7915a60>, args: (192.168.107.133, 6053, 0, 0, 6, 0), kwargs: {}
2021-09-17 07:34:00 DEBUG (MainThread) [homeassistant.util.executor] Calling executor with function: <function getaddrinfo at 0x7f96b7915a60>, args: (192.168.107.3, 6053, 0, 0, 6, 0), kwargs: {}
2021-09-17 07:34:00 DEBUG (MainThread) [homeassistant.util.executor] Calling executor with function: <function getaddrinfo at 0x7f96b7915a60>, args: (192.168.107.203, 6053, 0, 0, 6, 0), kwargs: {}
2021-09-17 07:34:00 DEBUG (MainThread) [homeassistant.util.executor] Calling executor with function: <function getaddrinfo at 0x7f96b7915a60>, args: (192.168.107.178, 6053, 0, 0, 6, 0), kwargs: {}
2021-09-17 07:34:00 DEBUG (MainThread) [homeassistant.util.executor] Calling executor with function: <function getaddrinfo at 0x7f96b7915a60>, args: (192.168.107.173, 6053, 0, 0, 6, 0), kwargs: {}
2021-09-17 07:34:00 DEBUG (MainThread) [homeassistant.util.executor] Calling executor with function: <function getaddrinfo at 0x7f96b7915a60>, args: (192.168.106.243, 6053, 0, 0, 6, 0), kwargs: {}
2021-09-17 07:34:00 DEBUG (MainThread) [homeassistant.util.executor] Calling executor with function: <function getaddrinfo at 0x7f96b7915a60>, args: (192.168.107.170, 6053, 0, 0, 6, 0), kwargs: {}

Similar to #26

Avoids executor overload at statup with lots of esphome devices

2021-09-17 07:34:00 DEBUG (MainThread) [homeassistant.util.executor] Calling executor with function: <function getaddrinfo at 0x7f96b7915a60>, args: (192.168.107.189, 6053, 0, 0, 6, 0), kwargs: {}
2021-09-17 07:34:00 DEBUG (MainThread) [homeassistant.util.executor] Calling executor with function: <function getaddrinfo at 0x7f96b7915a60>, args: (192.168.107.248, 6053, 0, 0, 6, 0), kwargs: {}
2021-09-17 07:34:00 DEBUG (MainThread) [homeassistant.util.executor] Calling executor with function: <function getaddrinfo at 0x7f96b7915a60>, args: (192.168.107.234, 6053, 0, 0, 6, 0), kwargs: {}
2021-09-17 07:34:00 DEBUG (MainThread) [homeassistant.util.executor] Calling executor with function: <function getaddrinfo at 0x7f96b7915a60>, args: (192.168.107.206, 6053, 0, 0, 6, 0), kwargs: {}
2021-09-17 07:34:00 DEBUG (MainThread) [homeassistant.util.executor] Calling executor with function: <function getaddrinfo at 0x7f96b7915a60>, args: (192.168.107.220, 6053, 0, 0, 6, 0), kwargs: {}
2021-09-17 07:34:00 DEBUG (MainThread) [homeassistant.util.executor] Calling executor with function: <function getaddrinfo at 0x7f96b7915a60>, args: (192.168.107.61, 6053, 0, 0, 6, 0), kwargs: {}
2021-09-17 07:34:00 DEBUG (MainThread) [homeassistant.util.executor] Calling executor with function: <function getaddrinfo at 0x7f96b7915a60>, args: (192.168.107.133, 6053, 0, 0, 6, 0), kwargs: {}
2021-09-17 07:34:00 DEBUG (MainThread) [homeassistant.util.executor] Calling executor with function: <function getaddrinfo at 0x7f96b7915a60>, args: (192.168.107.3, 6053, 0, 0, 6, 0), kwargs: {}
2021-09-17 07:34:00 DEBUG (MainThread) [homeassistant.util.executor] Calling executor with function: <function getaddrinfo at 0x7f96b7915a60>, args: (192.168.107.203, 6053, 0, 0, 6, 0), kwargs: {}
2021-09-17 07:34:00 DEBUG (MainThread) [homeassistant.util.executor] Calling executor with function: <function getaddrinfo at 0x7f96b7915a60>, args: (192.168.107.178, 6053, 0, 0, 6, 0), kwargs: {}
2021-09-17 07:34:00 DEBUG (MainThread) [homeassistant.util.executor] Calling executor with function: <function getaddrinfo at 0x7f96b7915a60>, args: (192.168.107.173, 6053, 0, 0, 6, 0), kwargs: {}
2021-09-17 07:34:00 DEBUG (MainThread) [homeassistant.util.executor] Calling executor with function: <function getaddrinfo at 0x7f96b7915a60>, args: (192.168.106.243, 6053, 0, 0, 6, 0), kwargs: {}
2021-09-17 07:34:00 DEBUG (MainThread) [homeassistant.util.executor] Calling executor with function: <function getaddrinfo at 0x7f96b7915a60>, args: (192.168.107.170, 6053, 0, 0, 6, 0), kwargs: {}
@bdraco bdraco marked this pull request as ready for review September 17, 2021 07:59
@bdraco
Copy link
Member Author

bdraco commented Sep 17, 2021

Tested on HASS Dev with manually upgrading to this version.

My esphome devices still work and no executor use on startup

@bdraco
Copy link
Member Author

bdraco commented Sep 17, 2021

Using a custom def submit in the thread pool to watch executor calls : https://github.com/bdraco/home-assistant/blob/integration/homeassistant/util/executor.py#L65

@bdraco
Copy link
Member Author

bdraco commented Sep 17, 2021

Reduced esphome startup time from 23.12 s to 9.63 s on one of my production installs

@OttoWinter
Copy link
Member

Reduced esphome startup time from 23.12 s to 9.63 s on one of my production installs

😱 how many esphome devices do you have???

I know the threadpool isn't very fast (or rather the synchronization) but I never expected it to be that slow. Do you know how much latency I can expect from executor calls?

@OttoWinter OttoWinter merged commit 2e22b23 into esphome:main Sep 17, 2021
@bdraco
Copy link
Member Author

bdraco commented Sep 17, 2021

The install I was testing on only had 42. The executor execution is really quick except when there are a lot of sync integrations competing for it at startup (or on installs that have a lot of sync integration updating frequently -- these are where we still have a major UX issue, and why I've been investing time in converting the top integrations to asyncio). If esphome is unlucky enough to startup when the executor is in an overload state everything would wait. Once we hit 64 workers everything grinds to a halt that is waiting for the executor even if the executor job itself will be quick because it may be in line behind one that is not. (https://github.com/home-assistant/core/blob/dev/homeassistant/runner.py#L28).

With python-zeroconf we had to add 10s to each timeout that hit the executor to avoid timeouts that would only present at startup. python-zeroconf/python-zeroconf#895

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