Repository navigation
fix(executions): write execution snapshots without ClickHouse async insert - #14652
Conversation
…nsert ClickHouse 26.x enables async_insert with wait_for_async_insert by default, so every one-row execution snapshot waited up to 200ms for a buffer flush. With the default pool of two connections the executions worker topped out near 11 writes per second, and the queue backed up far enough that getExecution kept returning 404 for executions the API had already accepted.
|
Review complete. No issues found — approved ✅. This PR adds
Reviewed commit: e3c8894 |
🟢 Tier S · Ready to merge
Execution snapshot writes now set ClickHouse
📂 Walkthrough · 2
Reviewed |
Security rulesNo new WARNING or ERROR findings from security rules. 19 existing findings tracked in
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
What does this PR do?
Writes execution snapshots to ClickHouse with
async_insert=0, so each insert returns as soon as its part is written instead of waiting for ClickHouse's async insert buffer to flush.Why
POST /v1/functions/{functionId}/executionsreturns the execution$idbefore the execution is stored. The snapshot goesExecutionScheduled/ExecutionCompleted→Loglistener →v1-executionsqueue → executions worker →Store::upsert(), whileGET /v1/functions/{functionId}/executions/{executionId}reads only from the store. Until the worker writes the row, polling the returned id gives404 execution_not_found. This was reported by a self-hosted 2.5.x user who runs long AI jobs async and pollsgetExecutionfor completion.The write itself is the bottleneck. ClickHouse 26.x ships with
async_insert=1andwait_for_async_insert=1as server defaults, andStorenever overrode them. Every snapshot is one row, so each insert waited out the adaptive busy timeout (50–200 ms) for a flush that had almost nothing to batch:_APP_POOL_SIZE_EXECUTIONS), so the worker caps at 2 / 0.175 s ≈ 11 writes/s. Measured drain rate: 11/s.getExecution404s.With
async_insert=0the same insert takes 3–5 ms.Alternatives considered and rejected
async_insert=0it still halved throughput under concurrency. Not worth it for a read-after-write guarantee on one endpoint.Test Plan
Unit
tests/unit/Execution/StoreTest.php::testWritesBypassAsyncInsertBufferasserts every insert (upsert and delete snapshots) sendsasync_insert=0. It fails onmain(Failed asserting that null is identical to '0') and passes with this change. The fullStoreTestpasses (21 tests). Pint, PHPStan and Rector are clean.Benchmark
Setup: stock
appwrite/appwrite:2.5.0docker compose stack (ClickHouse 26.4.3.37, default.env, combined worker) on a 12-CPU / 20 GB Docker host, with a Node 22 function that returns immediately. The patched variant swaps onlyStore.phpinside the same containers. Each phase waits for the functions and executions queues to drain before starting. Rounds were interleaved to limit drift: A was measured twice, D once. The "queued writes" columns show how far the executions worker fell behind by the end of each phase, and how long it took to catch up. That catch-up time is the worst-case window in whichgetExecutionreturns 404.ClickHouse
system.query_logfor the same runs (3,270 execution inserts per round):Create latency is unchanged within noise: the API path never touched the insert. Merges kept up easily without the buffer, and active parts stayed in single digits.
Create → immediate GET on the same stack, with the race window measured until GET returns 200:
A short window remains, because the snapshot still goes through the queue. But the delay now stays in the tens of milliseconds instead of growing with load to minutes.
Related PRs and Issues
createExecutionreturns 202 with an id thatgetExecution404s until ClickHouse persistence.Checklist
Closes #14654