Skip to content

Make ClickhouseRepo query timeout and max_execution_time configurable via env vars - #6691

Open
sp-kjablonski wants to merge 1 commit into
plausible:masterfrom
sp-kjablonski:configurable-clickhouse-query-timeout
Open

sp-kjablonski wants to merge 1 commit into
plausible:masterfrom
sp-kjablonski:configurable-clickhouse-query-timeout

Conversation

@sp-kjablonski

Copy link
Copy Markdown

Changes

Addresses plausible/community-edition#277 (see also plausible/community-edition#75 and #4359).

Since #6018, Plausible.ClickhouseRepo runs stats queries with two hardcoded limits in config/runtime.exs: a client-side timeout: 15_000 and a server-side ClickHouse setting max_execution_time: 20. There was no way to change either on Community Edition short of building a custom image, so on a high-traffic site any dashboard query taking longer than 15s (e.g. month-long period + with_imported=true + event:props:* filters) fails with DBConnection.ConnectionError ... timed out because it queued and checked out the connection for longer than 15000ms.

This PR makes both values configurable via environment variables while keeping the current values as defaults:

Variable Meaning Default
CLICKHOUSE_QUERY_TIMEOUT_MS ClickhouseRepo connection :timeout for stats queries 15000 (unchanged)
CLICKHOUSE_MAX_EXECUTION_TIME_SEC ClickHouse max_execution_time setting CLICKHOUSE_QUERY_TIMEOUT_MS / 1000 + 5, i.e. 20 (unchanged)

Deriving the server-side limit from the client timeout keeps the existing invariant (server limit slightly above client timeout) without requiring self-hosters to tune two knobs; the second variable is there for those who want to override it explicitly. Nothing changes for deployments that don't set these variables.

Tests

  • Automated tests have been added

Added a describe "clickhouse" block to test/plausible/config_test.exs covering the defaults, CLICKHOUSE_QUERY_TIMEOUT_MS alone (with derived max_execution_time), both variables together, and a non-integer value raising.

Changelog

  • Entry has been added to changelog

Documentation

  • Docs have been updated

The relevant place is the CE wiki Configuration page (Database section), which I can't open a PR against. Suggested text:

CLICKHOUSE_QUERY_TIMEOUT_MS

Default: 15000

Timeout in milliseconds for dashboard/stats queries against ClickHouse. Increase it if the dashboard errors out with timed out because it queued and checked out the connection for longer than 15000ms on large sites.

CLICKHOUSE_MAX_EXECUTION_TIME_SEC

Default: CLICKHOUSE_QUERY_TIMEOUT_MS / 1000 + 5 (20)

Server-side ClickHouse max_execution_time for stats queries, in seconds. Only needs to be set explicitly if you want a different margin above CLICKHOUSE_QUERY_TIMEOUT_MS.

Dark mode

  • This PR does not change the UI

🤖 Generated with Claude Code

Since plausible#6018 stats queries against ClickHouse have been limited by a
hardcoded 15s client-side timeout and a 20s server-side
max_execution_time, with no way to change either on Community Edition
short of building a custom image.

Read both from CLICKHOUSE_QUERY_TIMEOUT_MS and
CLICKHOUSE_MAX_EXECUTION_TIME_SEC. The current values stay as defaults,
and max_execution_time defaults to the client timeout in seconds + 5 so
the server-side limit keeps sitting slightly above the client one.

Ref plausible/community-edition#277
@CLAassistant

CLAassistant commented Sep 20, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants