Repository navigation
Description
Purpose of the feature.
The standalone DocumentDB gateway builds its Tokio multi-threaded runtime with a
worker-thread count that defaults to the number of visible logical CPUs
(std::thread::available_parallelism()), with no upper bound and no
environment-variable override. On large hosts (many cores, or bare metal), the
gateway spawns roughly one worker thread per core regardless of actual load. This
inflates the gateway's baseline memory footprint (thread stacks + per-worker
runtime structures) and makes the footprint unpredictable — which matters when the
gateway is co-located with PostgreSQL or packed densely on a node.
Current behavior (on main):
pg_documentdb_gw/documentdb_gateway/src/main.rs:57-59builds the runtime with
.worker_threads(setup_configuration.async_runtime_worker_threads()).pg_documentdb_gw/documentdb_gateway_core/src/configuration/setup.rs:932-938—
when unset,async_runtime_worker_threadsfalls back to
available_parallelism()(i.e. all visible CPUs, floored at 1).- The field
async_runtime_worker_threads: Option<usize>
(setup.rs:99) is only settable via the JSON setup configuration. The
recognized environment variables (env_keys,setup.rs:23-47) are limited to
DOCUMENTDB_PG_URL_FILE,DOCUMENTDB_LISTEN_ADDR,DOCUMENTDB_TLS_*, and
DOCUMENTDB_LOG_LEVEL— there is no env var for worker threads.
Net effect: there is no ergonomic way to cap the gateway's runtime thread count,
and the out-of-the-box default is "use every CPU on the machine."
Describe the solution you'd like
- A reasonable bounded default when
async_runtime_worker_threadsis unset,
instead of "all CPUs" — e.g.min(available_parallelism(), N)for a small,
documentedN, or a default derived from a documented heuristic. (The exact
number is open for discussion.) - An environment-variable override (e.g.
DOCUMENTDB_ASYNC_RUNTIME_WORKER_THREADS) wired throughapply_env_overlays,
so deployments can tune/cap the thread count without editing JSON config or
rebuilding — including bare-metal deployments where there is no cgroup CPU
limit to constrainavailable_parallelism(). - Log and document the resolved value (the count is already logged at
main.rs:64); document the new knob and its precedence.
Describe alternatives you've considered
- Cgroup CPU limit: in containers,
available_parallelism()is cgroup-aware
on modern Linux/Rust, so a CPU limit indirectly caps the thread count. This does
not help bare-metal / no-cgroup deployments, and it couples thread count to CPU
quota, which is not always desirable. - OS CPU affinity (taskset/cpuset/numactl): works on bare metal but is
operationally awkward and not discoverable. - Status quo (JSON-only field): requires shipping/managing a config file just
to cap threads; no env-var ergonomics.
Additional context
Scenarios to validate:
- Start the gateway on a many-core host with no override → worker-thread count is
the new bounded default (not the core count); confirm via the startup log line. - Set
DOCUMENTDB_ASYNC_RUNTIME_WORKER_THREADS=2→ exactly 2 worker threads
regardless of host core count; verify reduced RSS at idle. - Explicit JSON
AsyncRuntimeWorkerThreadsstill works; define and document
precedence between the env var and the JSON field. - Invalid / zero value → rejected or clamped to
>= 1with a clear message.
Activity
documentdb-triage-tool commentedon Jul 8, 2026
👋 @AndrewKhoma — this issue has been assigned for 14 days with no activity. Is it still in progress? If you've made progress, please leave a quick update. Otherwise it'll be flagged for re-assignment at the next triage meeting.
documentdb-triage-tool commentedon Jul 23, 2026
👋 @AndrewKhoma — this issue has been assigned for 14 days with no activity. Is it still in progress? If you've made progress, please leave a quick update. Otherwise it'll be flagged for re-assignment at the next triage meeting.
documentdb-triage-tool commentedon Aug 7, 2026
👋 @AndrewKhoma — this issue has been assigned for 14 days with no activity. Is it still in progress? If you've made progress, please leave a quick update. Otherwise it'll be flagged for re-assignment at the next triage meeting.
AndrewKhoma commentedon Aug 7, 2026
@xgerman did you tried setting the TOKIO_WORKER_THREADS? Looks like environment variable you've been looking for. And I don't think it should be part of the gateway since we need to utilize all of the available resources
documentdb-triage-tool commentedon Aug 22, 2026
👋 @AndrewKhoma — this issue has been assigned for 14 days with no activity. Is it still in progress? If you've made progress, please leave a quick update. Otherwise it'll be flagged for re-assignment at the next triage meeting.
documentdb-triage-tool commentedon Sep 5, 2026
👋 @AndrewKhoma — this issue has been assigned for 14 days with no activity. Is it still in progress? If you've made progress, please leave a quick update. Otherwise it'll be flagged for re-assignment at the next triage meeting.
documentdb-triage-tool commentedon Sep 19, 2026
👋 @AndrewKhoma — this issue has been assigned for 14 days with no activity. Is it still in progress? If you've made progress, please leave a quick update. Otherwise it'll be flagged for re-assignment at the next triage meeting.
documentdb-triage-tool commentedon Oct 3, 2026
👋 @AndrewKhoma — this issue has been assigned for 14 days with no activity. Is it still in progress? If you've made progress, please leave a quick update. Otherwise it'll be flagged for re-assignment at the next triage meeting.
documentdb-triage-tool commentedon Oct 28, 2026
👋 @AndrewKhoma — this issue has been assigned for 25 days with no activity. Is it still in progress? If you've made progress, please leave a quick update. Otherwise it'll be flagged for re-assignment at the next triage meeting.
documentdb-triage-tool commentedon Nov 17, 2026
👋 @tsharp, @AndrewKhoma — this issue has been assigned for 14 days with no activity. Is it still in progress? If you've made progress, please leave a quick update. Otherwise it'll be flagged for re-assignment at the next triage meeting.