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

FRITZ!Box Tools integrations using too many executor threads #114423

Closed
TheFes opened this issue Mar 29, 2024 · 3 comments · Fixed by #114570
Closed

FRITZ!Box Tools integrations using too many executor threads #114423

TheFes opened this issue Mar 29, 2024 · 3 comments · Fixed by #114570
Assignees
Milestone

Comments

@TheFes
Copy link
Contributor

TheFes commented Mar 29, 2024

The problem

After installing the 2024.4 beta I went through some tests together with @bdraco to investigate the slow startup of my system. We noticed that my system was using over 64 executor threads. After disabling the fritz integration and restarting this was reduced to 24.
(log output of profiler.log_thread_frames)

2024-03-27 21:43:02.544 CRITICAL (MainThread) [homeassistant.components.profiler] Thread [SyncWorker_63]: File "/usr/local/lib/python3.12/threading.py", line 1030, in _bootstrap
    self._bootstrap_inner()
  File "/usr/local/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.12/threading.py", line 1010, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 89, in _worker
    work_item = work_queue.get(block=True)

Nick specifically pointed out this part of the code

            for key in list(self._entity_update_functions):
                _LOGGER.debug("update entity %s", key)
                entity_data["entity_states"][
                    key
                ] = await self.hass.async_add_executor_job(
                    self._entity_update_functions[key],
                    self.fritz_status,
                    self.data["entity_states"].get(key),
                )

I was adviced to create an issue on this, as the usage of executor threads by fritz can cause issues for other processes requiring them.

What version of Home Assistant Core has the issue?

2024.4.0b0

What was the last working version of Home Assistant Core?

NA

What type of installation are you running?

Home Assistant OS

Integration causing the issue

AVM FRITZ!Box Tools

Link to integration documentation on our website

https://www.home-assistant.io/integrations/fritz/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

@home-assistant
Copy link

Hey there @mammuth, @AaronDavidSchneider, @chemelli74, @mib1185, mind taking a look at this issue as it has been labeled with an integration (fritz) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of fritz can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign fritz Removes the current integration label and assignees on the issue, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


fritz documentation
fritz source
(message by IssueLinks)

@frenck frenck added this to the 2024.4.0 milestone Mar 29, 2024
@mib1185
Copy link
Contributor

mib1185 commented Mar 29, 2024

Because of Easter holidays, I can't check it before Monday, but will do on Monday

@mib1185
Copy link
Contributor

mib1185 commented Mar 30, 2024

I think it would be sufficient to put this loop into a separate function and called it once as an executer job?

for key in list(self._entity_update_functions):
_LOGGER.debug("update entity %s", key)
entity_data["entity_states"][
key
] = await self.hass.async_add_executor_job(
self._entity_update_functions[key],
self.fritz_status,
self.data["entity_states"].get(key),
)

@github-actions github-actions bot locked and limited conversation to collaborators May 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants