Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@jgaalen
Copy link
Contributor

@jgaalen jgaalen commented Jan 5, 2025

Proposed change

This change makes the influxdb batch size and batch timeout configurable, rather than a fixed default of size: 100 and timeout: 1. It also fixes the timeout behaviour. Before, it waits for new events/values for the timeout (1s), but when values are received after 800ms, it waits for 1s again, causing situations where I had situations where it took more than 5 seconds before values are written.
This change makes it possible to write values quicker to influxdb, for a more realtime experience, or make larger batches and higher timeouts for lesser writes.

These values can be used in the influxdb yaml section:

  batch_buffer_size: 100
  batch_timeout: 0.1

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)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: -
  • 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
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format 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.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

home-assistant[bot]

This comment was marked as resolved.

@home-assistant home-assistant bot marked this pull request as draft January 5, 2025 10:49
@home-assistant
Copy link

home-assistant bot commented Jan 5, 2025

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@home-assistant
Copy link

home-assistant bot commented Jan 5, 2025

Hey there @mdegat01, mind taking a look at this pull request as it has been labeled with an integration (influxdb) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of influxdb can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign influxdb Removes the current integration label and assignees on the pull request, 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 pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

home-assistant[bot]

This comment was marked as resolved.

@jgaalen
Copy link
Contributor Author

jgaalen commented Jan 7, 2025

What is necessary to get this PR going?

@jgaalen
Copy link
Contributor Author

jgaalen commented Feb 7, 2025

@mdegat01 So this PR is open for a while. What is that about?

@jgaalen jgaalen marked this pull request as ready for review February 24, 2025 05:56
@home-assistant home-assistant bot dismissed stale reviews from themself February 24, 2025 05:56

Stale

@github-actions
Copy link

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

@github-actions github-actions bot added the stale label Apr 25, 2025
@jgaalen
Copy link
Contributor Author

jgaalen commented Apr 25, 2025

@mdegat01 Hi, this PR is here now for a couple of months. Can you take a look please? Thanks

@github-actions github-actions bot removed the stale label Apr 25, 2025
Copy link
Member

@joostlek joostlek left a comment

Choose a reason for hiding this comment

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

I believe influxdb is an exception, but ideally we should not change YAML config anymore. There's a PR open to bring InfluxDB to the UI so I think it would be better to look at that PR and add it after that PR is merged

@emontnemery
Copy link
Contributor

FTR, the other PR is this one: #134463

@github-actions
Copy link

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

@github-actions github-actions bot added the stale label Aug 24, 2025
@emontnemery
Copy link
Contributor

Not stale

@emontnemery emontnemery removed the stale label Aug 27, 2025
@github-actions
Copy link

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

@github-actions github-actions bot added the stale label Oct 26, 2025
@emontnemery
Copy link
Contributor

The config flow PR is still not ready for merge. @RobBie1221 do you see a problem with merging this PR first?

@github-actions github-actions bot removed the stale label Oct 27, 2025
@RobBie1221
Copy link
Contributor

No, I can deal with the conflicts.

Copy link
Contributor

@mdegat01 mdegat01 left a comment

Choose a reason for hiding this comment

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

Sorry for the delay. I'm good with this PR though searching influx documentation I notice a couple things:

  1. It says the optimal batch size for Influx v2 is 5000 lines. So maybe we want to increase the default there.
  2. Users of the cloud service need to be aware that it has it has hard limits here. In particular the free tier of Influx v2 cloud has a hard limit of 1MB/min. Since it only applies to free tier and cloud I don't know if we want to try and account for this in config schema but the corresponding documentation should note this.

@jgaalen
Copy link
Contributor Author

jgaalen commented Oct 27, 2025

Sorry for the delay. I'm good with this PR though searching influx documentation I notice a couple things:

  1. It says the optimal batch size for Influx v2 is 5000 lines. So maybe we want to increase the default there.

To reach 5000 lines within the set delay, you probably need a hell of a lot lines. Basically the batch size is simply an upper limit of lines to add within the set timeout.

  1. Users of the cloud service need to be aware that it has it has hard limits here. In particular the free tier of Influx v2 cloud has a hard limit of 1MB/min. Since it only applies to free tier and cloud I don't know if we want to try and account for this in config schema but the corresponding documentation should note this.

A good practise is to compress (gzip) the influx request payload to lower throughput and improve response times. For HA usually overkill.

@emontnemery emontnemery merged commit 0e2a460 into home-assistant:dev Nov 4, 2025
36 checks passed
"""Return a batch of events formatted for writing."""
queue_seconds = QUEUE_BACKLOG_SECONDS + self.max_tries * RETRY_DELAY
start_time = time.monotonic()
batch_timeout = self.batch_timeout()
Copy link
Member

Choose a reason for hiding this comment

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

This looks like an error. batch_timeout is now a property which returns a float so this will raise a TypeError. From the test logs

tests/components/influxdb/test_sensor.py: 25 warnings
  /home/runner/work/ha-core/ha-core/venv/lib/python3.13/site-packages/_pytest/threadexception.py:58:
    PytestUnhandledThreadExceptionWarning: Exception in thread influxdb
  
  Traceback (most recent call last):
    File "/opt/hostedtoolcache/Python/3.13.9/x64/lib/python3.13/threading.py", line 1043, in _bootstrap_inner
      self.run()
      ~~~~~~~~^^
    File "/home/runner/work/ha-core/ha-core/homeassistant/components/influxdb/__init__.py", line 618, in run
      _, json = self.get_events_json()
                ~~~~~~~~~~~~~~~~~~~~^^
    File "/home/runner/work/ha-core/ha-core/homeassistant/components/influxdb/__init__.py", line 554, in get_events_json
      batch_timeout = self.batch_timeout()
  TypeError: 'float' object is not callable

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.

7 participants