Skip to content

Reduce context switching in homekit state updates#35147

Merged
balloob merged 5 commits intohome-assistant:devfrom
bdraco:homekit_updates_dont_do_io
May 11, 2020
Merged

Reduce context switching in homekit state updates#35147
balloob merged 5 commits intohome-assistant:devfrom
bdraco:homekit_updates_dont_do_io

Conversation

@bdraco
Copy link
Copy Markdown
Member

@bdraco bdraco commented May 3, 2020

Proposed change

HomeKit state updates were running in the executor
but this does not appear to be needed as value
changes do not do IO and get pushed into a queue
where another thread takes care of updating the
controllers.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example entry for configuration.yaml:

# Example configuration.yaml

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

@bdraco
Copy link
Copy Markdown
Member Author

bdraco commented May 3, 2020

@MartinHjelmare I had incorrectly assumed that .set_value was doing I/O. I did some more investigation after #34975 and found all the I/O happens in another thread so I think its safe to simplify things a bit. Please let me know if I've missed something here.

https://github.com/ikalchev/HAP-python/blob/dev/pyhap/accessory_driver.py#L432

2020-05-03 18:45:57 DEBUG (MainThread) [pyhap.characteristic] set_value: TargetHeatingCoolingState to 3
2020-05-03 18:45:57 DEBUG (MainThread) [pyhap.characteristic] set_value: CurrentTemperature to 23.3
2020-05-03 18:45:57 DEBUG (Thread-47) [pyhap.accessory_driver] Send event: topic(699270554.10), data(b'{"characteristics": [{"aid": 699270554, "iid": 10, "value": 3}]}'), sender_client_addr(None)
2020-05-03 18:45:57 DEBUG (MainThread) [pyhap.characteristic] set_value: CoolingThresholdTemperature to 22.8
2020-05-03 18:45:57 DEBUG (Thread-47) [pyhap.accessory_driver] Sending event to client: ('192.168.209.53', 58601)
2020-05-03 18:45:57 DEBUG (Thread-47) [pyhap.accessory_driver] Sending event to client: ('192.168.209.57', 56334)
2020-05-03 18:45:57 DEBUG (Thread-47) [pyhap.accessory_driver] Sending event to client: ('192.168.210.42', 63813)
2020-05-03 18:45:57 DEBUG (Thread-47) [pyhap.accessory_driver] Send event: topic(699270554.11), data(b'{"characteristics": [{"aid": 699270554, "iid": 11, "value": 23.3}]}'), sender_client_addr(None)
2020-05-03 18:45:57 DEBUG (Thread-47) [pyhap.accessory_driver] Sending event to client: ('192.168.209.53', 58601)
2020-05-03 18:45:57 DEBUG (Thread-47) [pyhap.accessory_driver] Sending event to client: ('192.168.209.57', 56334)
2020-05-03 18:45:57 DEBUG (Thread-47) [pyhap.accessory_driver] Sending event to client: ('192.168.210.42', 63813)
2020-05-03 18:45:57 DEBUG (Thread-47) [pyhap.accessory_driver] Send event: topic(699270554.14), data(b'{"characteristics": [{"aid": 699270554, "iid": 14, "value": 22.8}]}'), sender_client_addr(None)
2020-05-03 18:45:57 DEBUG (Thread-47) [pyhap.accessory_driver] Sending event to client: ('192.168.209.53', 58601)
2020-05-03 18:45:57 DEBUG (Thread-47) [pyhap.accessory_driver] Sending event to client: ('192.168.209.57', 56334)
2020-05-03 18:45:57 DEBUG (Thread-47) [pyhap.accessory_driver] Sending event to client: ('192.168.210.42', 63813)

Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

It's hard for me to comment as I don't have the full picture of this integration and library.

Comment thread homeassistant/components/homekit/type_covers.py Outdated
Comment thread tests/components/homekit/test_accessories.py Outdated
@bdraco bdraco force-pushed the homekit_updates_dont_do_io branch 3 times, most recently from 72ec281 to 3c0c959 Compare May 7, 2020 23:12
bdraco added 5 commits May 8, 2020 04:27
HomeKit state updates were running in the executor
but this does not appear to be needed as value
changes do not do IO and get pushed into a queue
where another thread takes care of updating the
controllers.
@balloob balloob merged commit 742e36b into home-assistant:dev May 11, 2020
@lock lock Bot locked and limited conversation to collaborators May 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants