Execution modes and resource profiles

sxs separates three concerns that must not be confused:

  • Delivery — whether a data request is synchronous or an asynchronous export;
  • Execution mode — where synchronous data work runs: main-loop or worker;
  • Resource profile — how ClickHouse executes the query: normal or bulk.

Capacity (MODES) is a fourth, process-level concern: it decides what a process is allowed to execute.

A synchronous request therefore has both an execution mode and a resource profile. The two are independent: worker does not imply bulk, and bulk does not imply worker.

The axes

AxisQuestionValuesSelected by
DeliveryIs the response synchronous?sync, exportAPI used, Prefer: respond-async
Execution modeWhere does synchronous data run?main-loop, workerWORKER_OBS_COUNT_LIMIT, history flags, worker availability
Resource profileHow does ClickHouse execute the query?normal, bulkBULK_OBS_COUNT_LIMIT, request shape
CapacityWhat may this process execute?sdmx, loader, rpc, workers, exportsMODES

Classification thresholds

Three settings drive classification:

Environment settingSpace settingDefaultEffect when exceeded
WORKER_OBS_COUNT_LIMITworkerObsCountLimitunset (infinite)Run the request in a worker
BULK_OBS_COUNT_LIMITbulkObsCountLimitunset (infinite)Use the bulk resource profile
SYNC_MAX_OBSERVATIONSsyncMaxObservations5000000Reject synchronous requests with 413 Payload Too Large

The thresholds are independent. For example, with 10000 / 50000 / 5000000:

Result sizeExecution modeResource profile
5kmain-loopnormal
20kworkernormal
60kworkerbulk
> 5M413not executed

This example is illustrative. The default worker and bulk thresholds are infinite, so existing deployments are unchanged unless a threshold is set.

A request that exceeds SYNC_MAX_OBSERVATIONS is rejected with 413 unless it is an asynchronous export. Exports use EXPORT_MAX_OBSERVATIONS instead and bypass the synchronous cap.

How a request is classified

For SDMX-JSON and SDMX-CSV requests, classification follows these rules:

  1. A dimension-group-only request stays main-loop / normal.
  2. When the request has a limit lower than or equal to both thresholds, it stays main-loop / normal.
  3. When the dataset total is lower than or equal to both thresholds, it stays main-loop / normal.
  4. Otherwise sxs counts the selected result. For a limited request the selected page is the classification size; if that size is within both thresholds the request stays main-loop / normal.
  5. The execution mode is worker when the selected size exceeds the worker threshold; otherwise it remains main-loop.
  6. The resource profile is bulk when the selected size exceeds the bulk threshold; otherwise it remains normal.

For worker or bulk requests, the full filtered count is still recorded in the worker job for statistics and Content-Range.

Series requests always count the filtered observations, because a series limit/offset pages series rather than observations. Series limit and offset are honored but never capped.

includeHistory and updatedAfter force the worker execution mode. They do not force the bulk resource profile: a small history request is worker / normal, while a history request whose result exceeds the bulk threshold is worker / bulk.

Native formats bypass classification and the resource profile entirely. Native CSV, Parquet, Arrow, ArrowStream and Protobuf are streamed directly from ClickHouse and keep the normal cluster behaviour. They are still subject to the synchronous cap.

Multi-dataset requests are never offloaded to a worker. A multi-dataset request that contains a bulk resource query, or that uses history/updated-after, is rejected with 406.

Resource profiles

Normal

The normal profile is the interactive path:

  • the distributed ClickHouse table is used when the cluster is sharded;
  • normal cluster parallelism applies;
  • the observation query cache is eligible;
  • no bulk concurrency throttle is applied;
  • no worker job is created.

Bulk

The bulk profile protects ClickHouse from concurrent large extracts:

  • the local ClickHouse table is used instead of the distributed table;
  • max_threads = 1 and timeout_before_checking_execution_speed = 0.001;
  • max_execution_speed is reduced as running worker jobs increase;
  • the observation query cache is bypassed;
  • concurrency is throttled from the number of running bulk-resource worker jobs started in the last eight hours.
Running worker jobsmax_execution_speed
Fewer than 510M rows/s
Fewer than 101M rows/s
10 or more500K rows/s

Only worker_jobs records with resource: bulk count toward this throttle. Worker jobs with resource: normal do not consume bulk ClickHouse capacity.

Execution modes

Main-loop

The request is processed by the sxs main JavaScript thread. This is the lowest-latency path for small requests because there is no queue or thread handoff. It is also the most sensitive to CPU-bound work: a long build or serialization can delay other requests and health probes.

Worker

The ClickHouse query, SDMX building and JSON/CSV serialization run in a worker. The main thread keeps HTTP, queueing, response headers, backpressure and audit updates.

Worker locationSelectionTypical use
Local workerMODES=workers and a local worker poolDevelopment or all-in-one deploy
Remote workerNo workers capacity in the receiving sxs processsxs + wxs deployment

Worker eligibility currently requires SDMX JSON or non-native SDMX-CSV output, a single dataset, and an enabled worker pool. Native formats, dimension-group-only requests and multi-dataset requests stay in the main loop or stream directly from ClickHouse.

When a worker is not available, a request that would have used the worker falls back to the main loop with the same resource profile. Set WORKERS_ENABLED=false to disable both local worker execution and remote wxs dispatch entirely. The resource profile is still applied, so the fallback keeps the local-table and throttling behaviour.

Worker jobs

Each worker job is recorded in the per-space worker_jobs collection. The record includes:

  • queryId, dataset and dataset reference;
  • obsMode (obs or series);
  • executionMode (main-loop or worker);
  • resource (normal or bulk);
  • format, status, queuedAt and executionStartedAt;
  • the ClickHouse query and settings;
  • obsCount, seriesCount, runningBulks, host and node information;
  • worker runtime details, output size, cancellation and errors.

The status lifecycle is:

pending -> running -> done
                      |- failed
                      \- cancelled

Records created before the split used runningMode and did not have executionMode or resource. They are read as worker / bulk for backward compatibility.

The sxsWorkerJobs RPC service exposes loadAll, loadOne, stats and history. The old sxsBulks service is removed; Confy uses sxsWorkerJobs.

Capacities

MODES selects what a process is allowed to execute:

CapacityWorkTypical host
sdmxHTTP/SDMX structure and data queriessxs/lxs
loaderIngestion and background jobslxs
rpcAMQP request/response serviceslxs
workersLocal worker execution and wxs dispatchwxs
exportsExport queue consumption and file generationwxs

MODES=workers is a capacity switch:

  • it enables local worker execution;
  • without it, eligible worker jobs are sent to the remote wxs queue;
  • it does not mean “this process handles only bulk resource queries”;
  • it does not classify a request as normal or bulk.

A process with MODES=sdmx still serves normal, bulk and export APIs. It simply does not execute worker workloads locally.

Why the separation matters

  • The resource profile can be tuned independently from worker execution. A deployment can keep worker thresholds low for event-loop protection while keeping bulk thresholds high to avoid throttling ClickHouse.
  • History requests can be moved off the event loop without being treated as large ClickHouse extracts.
  • A worker can run normal-resource queries, so worker offload does not automatically consume bulk concurrency.
  • Native formats can keep their direct ClickHouse path without being classified as bulk.
  • A capacity can be added or removed without changing request classification.