Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

perf(clickhouse): back off the mutation poll instead of a fixed 15s sleep (#127433)

Raúl Negrón-Oteroad77b8a5a581
diff --git a/posthog/clickhouse/cluster.py b/posthog/clickhouse/cluster.py
index 9dcfa99d6a16..77e835c7186a 100644
--- a/posthog/clickhouse/cluster.py
+++ b/posthog/clickhouse/cluster.py
@@ -815,7 +815,11 @@ def _is_authentication_failure(e: Exception) -> bool:
_REJECTED_LOGIN_RETRY_POLICY = RetryPolicy(max_attempts=3, delay=5, exceptions=_is_authentication_failure)
-@dataclass
+MUTATION_POLL_INITIAL_SECONDS = 0.5
+MUTATION_POLL_MAX_SECONDS = 15.0
+
+
+@dataclass(frozen=True)
class MutationWaiter:
table: str
mutation_ids: Set[str]
@@ -848,8 +852,12 @@ class MutationWaiter:
return all(statuses.values())
def wait(self, client: Client) -> None:
+ # A small mutation finishes in well under a second, so the poll starts short. It backs off
+ # to MUTATION_POLL_MAX_SECONDS so that a long mutation does not flood system.mutations.
+ delay = MUTATION_POLL_INITIAL_SECONDS
while not self.is_done(client):
- time.sleep(15.0)
+ time.sleep(delay)
+ delay = min(delay * 2, MUTATION_POLL_MAX_SECONDS)
@dataclass