Skip to content

Admission gate for queries: FIFO queue with memory-aware admission for every remote protocol #9518

Description

@lvca

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.queryMaxConcurrent are running and the heap the running queries hold is below arcadedb.queryAdmissionHeapWatermark (percent of queryMaxHeapRAM). 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 when arcadedb.queryQueueMaxSize requests already wait, the request fails with QueryAdmissionException, 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.

Related: #9404, #9433.

Activity

  1. added
    concurrency
    enhancement
    observability
    server
    severity:minor
    on Oct 8, 2026
  2. self-assigned this
    on Oct 8, 2026
  3. added theissue type on Oct 8, 2026
  4. added this to the 26.11.1 milestone on Oct 8, 2026
  5. changed the title [-]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[/+] on Oct 8, 2026
  6. changed the title [-]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[/+] on Oct 8, 2026
  7. added
    in progress
    on Oct 8, 2026
  8. added 3 commits that reference this issue on Oct 8, 2026
  9. 4 remaining items

  10. removed
    in progress
    on Oct 8, 2026
  11. lvca commented on Oct 8, 2026

    @lvca
    MemberAuthor

    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.

    • It applies to every remote client: HTTP, Postgres, BOLT, Redis, gRPC, Gremlin Server, MCP and MongoDB. The embedded API is not affected.
    • A request starts when fewer than arcadedb.queryMaxConcurrent are running (default: 2 x CPU cores, at least 4) and the running queries hold less than arcadedb.queryAdmissionHeapWatermark (default 80%) of the query heap budget.
    • A request that waits longer than arcadedb.queryQueueTimeout (default 30 s), or finds arcadedb.queryQueueMaxSize requests already waiting (default 256), is refused with a retryable error (HTTP 503). Nothing of it ran, so you can retry it as is.
    • MongoDB requests never wait: one that cannot start at once is refused.
    • arcadedb.queryMaxConcurrent=0 restores 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.

  12. added 2 commits that reference this issue on Oct 9, 2026
  13. added 8 commits that reference this issue on Oct 21, 2026
  14. added a commit that references this issue on Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

concurrencyenhancementobservabilityperformanceserverseverity:minor

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions