Skip to content

Defer esphome persistent storage writes until after startup#42600

Merged
balloob merged 1 commit intohome-assistant:devfrom
bdraco:esphome_defer_startup
Oct 30, 2020
Merged

Defer esphome persistent storage writes until after startup#42600
balloob merged 1 commit intohome-assistant:devfrom
bdraco:esphome_defer_startup

Conversation

@bdraco
Copy link
Copy Markdown
Member

@bdraco bdraco commented Oct 29, 2020

Noticed because I have 35+ esphome devices.

Proposed change

Defer esphome persistent storage writes until after startup

Avoid disk I/O during startup as it can cause delays when
a user has many esphome devices.

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

To help with the load of incoming pull requests:

@probot-home-assistant
Copy link
Copy Markdown

Hey there @OttoWinter, mind taking a look at this pull request as its been labeled with an integration (esphome) you are listed as a codeowner for? Thanks!
(message by CodeOwnersMention)

@bdraco bdraco force-pushed the esphome_defer_startup branch from 1ae34ff to f83de92 Compare October 29, 2020 22:43
Copy link
Copy Markdown
Member

@balloob balloob Oct 29, 2020

Choose a reason for hiding this comment

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

Nice one.

We should find all the async_save and make them delays unless it's auth related (user/config entry).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'll audit what else is done at startup and adjust since these are the ones we except to be I/O bound since they are competing with loading the .py files from disk.

Avoid disk I/O during startup as it can cause delays when
a user has many esphome devices.
@bdraco bdraco force-pushed the esphome_defer_startup branch from f83de92 to 1445ca3 Compare October 29, 2020 23:07

DATA_KEY = "esphome"

SAVE_DELAY = 120
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this going to be okay? If there never will be 2 minutes of no data, it will never save until HA is shut down.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Should be fine since it only needs the data to re-setup the config entries with the last state before its able to make the connection to the device.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For other use cases, we could consider adding a max_wait to delay_save to make sure it's written eventually (besides on shutdown).

@balloob balloob merged commit 8a403cd into home-assistant:dev Oct 30, 2020
Thomas55555 pushed a commit to Thomas55555/core that referenced this pull request Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants