Skip to Content
Docs

Choose a Worker Size

Pick a starting size for a Worker, measure it under real work, and adjust CPU and memory with confidence.

A Worker's size sets the CPU and memory for each replica. Too small, and the Worker runs slowly, times out, or restarts. Too large, and it reserves capacity it never uses. This guide helps you choose a starting size, measure the Worker under real work, and adjust it.

The short version:

  1. Start at X-Small or Small unless your workload is clearly heavier. The starting points below cover the common cases.
  2. Test with real inputs at the volume you expect, including your largest input.
  3. Raise the resource that limits you, and only that one. Use a custom size when CPU and memory needs don't match a preset.

How Worker Sizing Works

The Size Covers the Whole Replica

Every container in a replica shares the replica's CPU and memory. That includes:

  • your application;
  • the managed host, for a managed Worker;
  • every service in a Compose Worker, such as a document converter or a cache.

A sidecar that converts documents can use more memory than the application that calls it. Size for everything in the replica, not just your own code.

Each replica also runs in its own isolated virtual machine. The platform reserves the sandbox's own overhead in addition to the size you choose, so don't subtract a sandbox amount from your configured memory. Inside the virtual machine, the guest system also uses some memory alongside your containers. Leave headroom above your measured peak rather than setting the memory limit to exactly that peak.

Requests and Limits

Each size has a request and a limit for CPU and for memory.

Request Limit
Meaning Capacity reserved for the replica. It is always available. The most the replica can use.
CPU The sustained amount of work you expect. Room to burst. Work above the limit is slowed down (throttled), not stopped.
Memory The memory the replica normally holds. The maximum memory the replica can use.

The difference matters when something goes wrong:

  • Not enough CPU makes a Worker slow. Requests take longer, events back up, and calls can time out. A replica that is starved of CPU for long enough can miss its health checks and be restarted.
  • Running out of memory can stop a container and interrupt its work. For an HTTP or event Worker, the platform can restart the affected container. If a managed event Worker stops before acknowledging an event, that event can be delivered again. If a scheduled run stops because it ran out of memory, the run fails without a retry. The next scheduled tick starts a new run.

More memory does not fix CPU throttling, and more CPU does not fix a memory leak or an unbounded buffer.

Size and Replicas Do Different Jobs

To get Change
More capacity for one invocation: a bigger file, a larger model, heavier parsing The size
More throughput: more events, requests, or users at once The replica count or scaling settings

How each trigger uses a replica affects its size:

  • Event Workers process one event at a time in each replica. Size for your largest single event. Scale throughput with replicas and backlog scaling.
  • HTTP Workers handle several requests at once in each replica. A managed HTTP Worker handles up to HTTP_CONCURRENCY requests at the same time (10 by default). Memory must cover all of them at once, so a Worker that buffers a 20 MB upload uses about 200 MB with 10 concurrent requests. Lower the concurrency or stream the data rather than only raising memory.
  • Scheduled Workers start a new replica for each run. Every run includes a cold start. Size for startup plus the job.

CPU-based scaling compares CPU use with the CPU request. A very small request makes a Worker scale out early, and a large request makes it scale out late. Set the request to the CPU the Worker really needs at steady load, then set Target CPU %.

Choose a Starting Point

The Size field in the admin console lists the presets available to your tenant. To see a preset's CPU and memory values, select Custom… and choose the preset under Start from.

Workload Start with Notes
Lightweight Rust or Go app: routing, record operations, calls to other services, streamed files XX-Small or X-Small Rust and Go apps use very little memory. Start at X-Small if your dependencies, payload sizes, or cold-start time are uncertain, and test XX-Small before you rely on it.
Lightweight Python app X-Small XX-Small can work with few dependencies and small inputs. Libraries such as pandas or NumPy, or large imported data, need more.
TypeScript or JavaScript app X-Small or Small Node.js has a larger fixed memory cost and needs room for garbage collection. Don't start at XX-Small.
Mostly waiting on AI, storage, or other APIs X-Small or Small Waiting doesn't use CPU. Memory still grows with the number of calls in flight and the size of each response.
CPU-heavy work: parsing, compression, image processing, encryption, local inference Small or Medium Raise CPU when the work is slow under steady load. Check whether your code can use more than one core before raising the limit above one core.
Memory-heavy work: loaded models, large in-memory datasets, OCR, document conversion Medium or larger Estimate from the loaded model or data, copies made while processing, and every service in the replica.
Scheduled job Same as the matching workload above Allow for startup time on every run.

Example: A Minimal Worker in Each Language

A managed event Worker whose handler only logs each event gives you a baseline for comparing runtimes. The figures below show approximate resource use under light load for the application and managed host combined. Memory reflects the working set at the time of sampling.

Application language Memory under light load CPU under light load
Rust 5 MiB 11 millicores
Go 9 MiB 15 millicores
Python 20 MiB 18 millicores
TypeScript 80 MiB 25 millicores

These numbers come from the images available at the time of sampling and show the relative baseline cost of each language. They are not a qualification of current images and not a prediction of what your Worker will use. Your dependencies, inputs, and concurrency add to them. Sandbox memory is not included.

Migrate From a Flow

Don't copy the size of the Flow Agent you are replacing. A Flow runs inside a Node-RED runtime with its own memory and CPU cost. A Worker runs only your code and, for a managed Worker, a small host. Many Flows move to a smaller Worker. Some move to a larger one, because a Worker that does more in a single invocation needs more for that invocation.

When you migrate:

  1. Find the Flow's heaviest step: the largest file, the biggest query result, or the slowest transform. Size the Worker for that step.
  2. Check how the Flow processes work. A Flow that handled one message at a time maps to an event Worker that processes one event per replica. A Flow that served HTTP maps to an HTTP Worker that handles several requests at once, and that multiplies memory.
  3. If the Flow read whole files into memory, use streaming in the Worker instead. Streamed files don't need memory in proportion to their size.
  4. Before you switch, compare processing time, errors, and restarts for the Worker and the Flow using representative inputs and traffic volumes. Include large payloads and busy periods where relevant.

Reduce What the Worker Needs

These changes often help more than a larger size:

  • Stream large files instead of reading them whole. A Worker can move files of hundreds of MB through a small, fixed amount of memory.
  • Limit concurrency. Bound parallel work inside an invocation, and lower HTTP_CONCURRENCY for an HTTP Worker that handles large requests. Running more calls at once doesn't always increase throughput. It can overload the service you're calling.
  • Process in batches. Read and write records in pages rather than loading a whole result set.
  • Reuse clients and load lazily. Create connections and load large libraries once, and only when you need them.
  • Package only what you use. Fewer dependencies mean faster starts and less memory.
  • Move heavy shared services out. If several Workers each run the same converter as a sidecar, consider one shared Worker for it.

Measure and Adjust

  1. Test realistic work. Use real input types and sizes, including the largest you support, at the concurrency or event rate you expect.

  2. Cover the whole lifecycle. Measure a cold start, repeated work once the Worker is warm, your largest input, and a sustained period of mixed traffic. A single successful run doesn't prove the size.

  3. Watch for the signs in the symptoms table. In the admin console, open the Worker and select Deployment to see instance status and restarts. Read logs with ctxl workers logs, and add --previous to read the run before a restart.

  4. Log your process's peak memory during testing. Short jobs can finish between platform measurements, so a high-water mark the process reports is more reliable:

    • Node.js: process.resourceUsage().maxRSS, in kilobytes. process.memoryUsage().rss is current memory, not the peak.
    • Python: resource.getrusage(resource.RUSAGE_SELF).ru_maxrss, in kilobytes on Linux.
    • Go, Rust, or any Linux process: the VmHWM line in /proc/self/status.

    This covers one process only. Add the managed host and any other containers separately when you compare with the Worker's size.

  5. Change one resource at a time, then test again, including a cold start.

  6. Set the final values:

    • Memory request: what the replica holds during normal work.
    • Memory limit: your measured peak plus a margin, such as 25 to 50 percent.
    • CPU request: what the Worker uses at steady load. To find that value, open the Worker’s Metrics tab and read an instance’s CPU usage in millicores during the steady portion of your test. The minimum custom CPU request is 25m.
    • CPU limit: room for bursts, such as startup or a large input.

    A custom size allows a CPU limit of up to 4 times its request and a memory limit of up to 2 times its request. See Configure a Custom Worker Size.

  7. Keep the previous version so you can roll back if the new size causes problems.

Saving a new size starts a deployment. Existing instances keep their size until they are replaced.

Recognize a Size Problem

What you see Likely cause What to do
Instances restart during large inputs or bursts, often with no error from your code Memory limit reached Raise memory, stream instead of buffering, or lower concurrency
Memory grows over hours until the replica restarts A leak or unbounded cache Fix the leak or bound the cache. More memory only delays the restart.
Work is slow or times out, and gets worse under load CPU throttling Raise the CPU request and limit, or reduce the work per invocation
Restarts during startup, or slow first responses after scaling up Too little CPU or memory to start the runtime and load dependencies Raise the size, or load dependencies lazily
Event backlog keeps growing while each replica works normally Not enough replicas Raise the maximum replicas or adjust backlog scaling, not the size
HTTP requests return 503 with Retry-After All concurrency slots are busy Add replicas, or raise HTTP_CONCURRENCY if memory and CPU allow it
The same event fails repeatedly and the replica restarts each time The container ran out of memory, or the event triggered an unhandled error Look for the exit reason under Metrics → Instance exits. If you don’t have Metrics access, check Deployment → Instance details while the replica still exists. If the reason is OOMKilled, reduce memory use or raise the memory limit. If the managed event Worker’s host container restarted, run ctxl workers logs <worker-id> -c host --previous to look for a handler error.

Checklist

  • [ ] The size covers every container in the replica, including sidecars.
  • [ ] You tested your largest input, a cold start, and sustained load.
  • [ ] Memory has headroom above the measured peak.
  • [ ] Each HTTP replica has enough memory for the requests it can handle at once.
  • [ ] Throughput comes from replicas, not a larger size.
  • [ ] Large files are streamed, not buffered.
  • [ ] You can roll back to the previous size.