Repository navigation
Description
Problem
Raised in #9404. The query heap budget (arcadedb.queryMaxHeapRAM, 26.11.1) makes a query fail with a retryable error (HTTP 503) when its buffers do not fit. That avoids the OutOfMemoryError, but the client still has to retry, and when several services retry independently the order of their requests is lost (batch 2 can be served before the tail of batch 1).
Instead of rejecting, the server should hold excess requests in a queue, in FIFO order, and start each one only when there is room for it.
Design: an admission gate, not an executor
The engine already runs many pools sized on the cores, and DatabaseAsyncExecutor is per database, so its threads multiply with the number of open databases. A new query executor would add to a thread budget that is already large. QueryAdmissionGate owns no threads: the thread that received the request parks while it waits.
- JVM-wide FIFO. Only the head of the queue can start, and a request that arrives while others wait queues behind them even if it could start at once.
- Admission rule. A request starts when fewer than
arcadedb.queryMaxConcurrentare running and the heap the running queries hold is belowarcadedb.queryAdmissionHeapWatermark(percent ofqueryMaxHeapRAM). When nothing admitted is running, the head starts whatever the heap, so a budget held by work outside the gate cannot stall the queue. - Wait only before the request starts, never mid-query. A query that holds part of the budget and waits for others would deadlock (hold-and-wait).
- Bounded. After
arcadedb.queryQueueTimeout, or whenarcadedb.queryQueueMaxSizerequests already wait, the request fails withQueryAdmissionException, retryable on every protocol. Nothing of it ran. - Nested queries share the slot. A query started on a thread that already holds a slot (a function, a script, an MCP tool) shares it instead of queueing behind its own caller.
- Forwarding gives the slot back. A follower releases its slot before forwarding a request to the leader: it does no work while it waits, and in a JVM that hosts several servers (the HA tests) it would otherwise starve the leader.
Settings
| Setting | Default | Notes |
|---|---|---|
arcadedb.queryMaxConcurrent |
2 x cores, at least 4 | 0 disables the gate |
arcadedb.queryAdmissionHeapWatermark |
80 | percent of queryMaxHeapRAM, 0 admits on the slot count alone |
arcadedb.queryQueueTimeout |
30000 ms | 0 does not wait |
arcadedb.queryQueueMaxSize |
256 (8 with low-ram) |
keep it below server.httpWorkerThreads |
Who goes through the gate
| Entry point | Behavior | Refusal |
|---|---|---|
| HTTP | Every database endpoint, in one place (DatabaseAbstractHandler, inside the session lock): query, command, vector search, time series, PromQL/Grafana. Batch loads too. Begin, rollback and the Grafana health probe are exempt. GET /query leaves the IO thread while the gate is enabled. |
503 |
| Postgres | Simple query, Describe/Execute, COPY. The slot goes back once the rows are materialized, before they are written. | SQLSTATE 40001 |
| BOLT | The slot belongs to the result stream until it is read to the end or discarded. A second stream of the same transaction shares it. | transient error |
| Redis | Every command but PING and SELECT. |
TRYAGAIN |
| gRPC | Unary and server-streaming RPCs of ArcadeDbService, through an interceptor. Begin/rollback and the admin service are exempt. |
ABORTED |
| Gremlin Server | Scripts and traversals, through the GraphManager query hooks. |
error response |
| MCP | Data tools. Status, settings and profiler tools are exempt. | tool error |
| MongoDB | Commands run on shared Netty threads, so it never waits: a request that cannot start at once is refused. | ExceededTimeLimit (262) |
Not gated (follow-ups)
- The embedded API: the server's own work (security, schema, replication, triggers) runs queries the same way.
database.async().query(): its slot workers also serve writes, so blocking one would stall them.- gRPC client-streaming loads (
InsertStream,InsertBidirectional,GraphBatchLoad,TimeSeriesWriteStream): a refusal between two chunks needs each stream's own error path. - Gremlin Server sessions.
Observability
Profiler counters queryAdmissionRunning, queryAdmissionQueued, queryAdmissionAdmitted, queryAdmissionAdmittedAfterWaiting, queryAdmissionRefused, queryAdmissionHeapDeferrals, queryAdmissionWaitTime. Micrometer row pool=query_admission, shown in Studio's Executor Pools card as "Query Admission Gate".
Verification
- Gate unit tests: FIFO order, timeout, full queue, heap-aware admission, first-query rule, nested slots, early release, cross-thread close, interrupt.
- One test per protocol: a request is refused with the protocol's retryable code while the only slot is taken, and every request gives its slot back. HTTP also covers waiting, a heavy query that would get a 503 from the heap budget waiting and then succeeding, and session rollback while every slot is taken.
- Existing suites green with the gate on by default: server, Postgres, BOLT, Redis, MongoDB, gRPC, MCP, Gremlin Server, ha-raft unit lane and follower-forwarding ITs.
Activity
[-]Admission control for queries: FIFO queue with memory-aware admission, used by the HTTP query handler[/-][+]Admission gate for queries: FIFO queue with memory-aware admission, used by the HTTP query handlers[/+][-]Admission gate for queries: FIFO queue with memory-aware admission, used by the HTTP query handlers[/-][+]Admission gate for queries: FIFO queue with memory-aware admission for every remote protocol[/+]review(#9518): admission before the session lock, slot covers the com…
review(#9518): compare the queue head and the thread's slot with equa…
test(#9518): a BOLT stream left open when its transaction ends gives …
4 remaining items
lvca commentedon Oct 8, 2026
Implemented in #9528 (26.11.1).
When the server is busy, requests now wait in a queue and start in arrival order, instead of all starting at once and the last ones being refused with 503 or exhausting the heap.
arcadedb.queryMaxConcurrentare running (default: 2 x CPU cores, at least 4) and the running queries hold less thanarcadedb.queryAdmissionHeapWatermark(default 80%) of the query heap budget.arcadedb.queryQueueTimeout(default 30 s), or findsarcadedb.queryQueueMaxSizerequests already waiting (default 256), is refused with a retryable error (HTTP 503). Nothing of it ran, so you can retry it as is.arcadedb.queryMaxConcurrent=0restores the previous behavior.You can watch the queue in Studio (Server tab, Executor Pools, "Query Admission Gate").
❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.
feat(ArcadeData#9518): query admission gate - FIFO queue with heap-aw…
feat(ArcadeData#9518): query admission gate for every remote protocol…
feat(#9518): query admission gate - FIFO queue with heap-aware admiss…
feat(#9518): query admission gate for every remote protocol, enabled …
review(#9518): admission before the session lock, slot covers the com…
review(#9518): compare the queue head and the thread's slot with equa…
test(#9518): a BOLT stream left open when its transaction ends gives …
test(#9518): gate under contention, and disabled while queries wait
test(#9518): a BOLT connection dropped mid-stream gives its slot back
fix(#9518): a request waiting for an explicit lock gives its admissio…
test(postgresw): consolidate the issue-named postgresw tests into top…
fix(ArcadeData#13052): the find cursor carries the resultSetLimit quo…