Skip to content

Reuse QuestDB sender#129

Merged
CM000n merged 3 commits intomainfrom
FIX_123/implement_QuestDB_sender_reuse
Oct 2, 2025
Merged

Reuse QuestDB sender#129
CM000n merged 3 commits intomainfrom
FIX_123/implement_QuestDB_sender_reuse

Conversation

@CM000n
Copy link
Copy Markdown
Owner

@CM000n CM000n commented Oct 2, 2025

The problem: The warning occurred because a new QuestDB sender was created and immediately destroyed for each state-changed event. This led to inefficient connection establishment/termination cycles.

The solution: I changed the architecture so that the QuestDB sender is created once when the QuestDB class is started and reused throughout the entire runtime.

Important changes:

  1. New _create_sender() method in the QuestDB class:
  • Creates a sender once based on the auth settings.
  • Supports both authenticated (TLS) and non-authenticated connections.
  1. Sender as instance variable:
  • The sender is stored as self.sender and reused.
  • It is closed properly during shutdown.
  1. Simplified IO functions:
  • Removal of _insert_row_with_auth and _insert_row_without_auth.
  • A single _insert_row() function that uses the provided sender.
  • Updated function signatures for better reusability.
  1. Improved shutdown handling:
  • The sender is closed properly during the Home Assistant stop event.

Result:

  • The warning is eliminated because the sender is only created once.
  • Better performance by avoiding repeated connection establishment.
  • Clean resource management with proper cleanup during shutdown.

The changes follow the best practices outlined in the QuestDB Python Client documentation and should completely eliminate the warning in Home Assistant logs.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Oct 2, 2025

@CM000n CM000n merged commit 31daaf2 into main Oct 2, 2025
11 checks passed
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.

UserWarning: questdb.ingress.Sender: Detected a burst of reconnections.

1 participant