Skip to content

fix: stop ClickHouse writing the diagnostics nothing reads - #13874

Merged
HarshMN2345 merged 5 commits into
codex/fix-clickhouse-log-retentionfrom
fix/clickhouse-idle-cpu
Oct 8, 2026
Merged

HarshMN2345 merged 5 commits into
codex/fix-clickhouse-log-retentionfrom
fix/clickhouse-idle-cpu

Conversation

@HarshMN2345

Copy link
Copy Markdown
Member

What does this PR do?

Stops the bundled ClickHouse from writing its own telemetry, which is what burns CPU on an idle self-hosted install.

Capping the system logs with a TTL (#13735, which this stacks on) bounds the disk they take, but not the work that produces them: asynchronous_metric_log and metric_log sample the server every second whether or not Appwrite is serving traffic, and every row still costs an insert plus the background merges behind it. On an idle stack, system.* logs accounted for ~95s of merge time per hour against 0.1s for every appwrite.* table combined, and asynchronous_metric_log alone wrote ~600k rows/hour with no traffic at all.

Nothing reads these tables — the only system. query in the codebase is a schema check against system.tables (src/Appwrite/Execution/Store.php:195) — so this removes the sections that produce them and keeps the ones with debugging value (query_log, part_log, error_log, query_views_log, asynchronous_insert_log, background_schedule_pool_log), still capped.

text_log goes too: it duplicates the server log the container already writes.

The init script needed a matching change. A log that is no longer written is never replaced either, so the existing table would sit on disk forever on an upgraded install — it now falls back to a 7-day TTL when there is no replacement to copy one from, and those rows drain instead.

Measured

Three ClickHouse 26.4.3 containers, 2 CPUs each, same host, idle, sampled every 8s for ~7 minutes:

config median CPU p90 max
TTL only (#13735) 7.00% 13.56% 32.47%
this PR 2.87% 4.38% 6.05%
this PR + asynchronous_metrics_update_period_s=30 5.04% 7.85% 9.82%

Raising the metrics period measurably made it worse, so it is not included.

Test Plan

Against real ClickHouse 26.4.3:

  • Fresh volume — asynchronous_metric_log, metric_log, histogram_metric_log, query_metric_log, trace_log, text_log and processors_profile_log are never created; query_log, part_log and the rest come up with their TTLs; no errors in the server log.
  • Upgrade from an unconfigured volume — old text_log (1772 rows), trace_log, metric_log and the retired *_log_0 tables all pick up a TTL and stop growing: 25 queries later text_log is still at 1772 while query_log climbed to 102.
  • Restart — re-running the init script over the migrated volume is a no-op.

Related PRs

Stacked on #13735; retarget to main once that merges.

Have you read the Contributing Guidelines on issues?

Yes.

@greptile-apps

greptile-apps Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge based on the reviewed changes.

Summary

The PR disables unused ClickHouse diagnostic logs and adds retention for log tables left on existing volumes. Since the previous review, it replaces regex-based log selection with string operations and preserves the init script’s executable mode when installing it.

Reviews (3) · Last reviewed commit: "Merge branch 'codex/fix-clickhouse-log-r..."

Comment thread clickhouse-init.sh Resolved
@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing codex/fix-clickhouse-log-retention (before) → fix/clickhouse-idle-cpu (after).

Metric Before After Change
🚀 Requests/sec 202.66 213.69 🟢 +5.4%
⏱️ Latency P50 85.67 ms 81.16 ms 🟢 -5.3%
⏱️ Latency P95 198.78 ms 190.01 ms ⚪ -4.4%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 81.16 190.01 13,623 213.69 -8.77
Account 155.13 284.55 717 11.98 -14.21
TablesDB 77.79 143.29 7,409 118.4 -22.45
Storage 76.41 163.35 3,585 59.17 +2.43
Functions 119.45 237.63 1,912 32.12 +13.02

Top API waits (after)

API request Max wait (ms)
functions.variables.update 470.17
account.name.update 422.78
account.prefs.update 422.27
tablesdb.rows.delete 397.68
tablesdb.rows.decrement 364.72

Comment thread clickhouse-init.sh Resolved
levivannoort and others added 2 commits September 24, 2026 17:02
…on' into fix/clickhouse-idle-cpu

# Conflicts:
#	clickhouse-config.xml
@ghost

ghost commented Oct 5, 2026

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

No concrete defects found in the configuration or migration logic after checking the startup wiring and existing test coverage.

Disables the bundled ClickHouse metric, trace, profile, and text logs while retaining capped logs useful for debugging. Updates initialization to apply a seven-day fallback TTL to abandoned log tables when no active replacement exists.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 2
File Change
clickhouse-config.xml Removes telemetry-producing log sections and retains TTLs on debugging logs.
clickhouse-init.sh Finds abandoned MergeTree log tables and applies the replacement TTL or a seven-day fallback.

Reviewed a15e790 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Tier S · Looks good to merge. Summary

@HarshMN2345
HarshMN2345 merged commit db9120a into codex/fix-clickhouse-log-retention Oct 8, 2026
51 checks passed
@HarshMN2345 HarshMN2345 mentioned this pull request Oct 9, 2026
2 tasks done
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