Concurrency
By default each worker runs one job at a time. Handlers that spend time waiting, or models that batch well, can process several jobs per worker to cut cost and queue time.
Two levels of concurrency
| Level | Controlled by | Default |
|---|---|---|
| Workers per endpoint | maxWorkers (and minWorkers) | 3 |
| Jobs per worker | concurrency_modifier in the handler | 1 |
| GPUs per organization | Plan concurrent-GPU limit (pods + workers) | 10 on Starter, 50 on Team |
Async handlers
To run more than one job per worker, write the handler as async def and return the desired concurrency from concurrency_modifier. The SDK pulls that many jobs from the queue and runs them on one event loop.
import apipods
from vllm import AsyncEngineArgs, AsyncLLMEngine, SamplingParams
engine = AsyncLLMEngine.from_engine_args(AsyncEngineArgs(model="Qwen/Qwen3-8B"))
async def handler(job):
params = SamplingParams(max_tokens=job["input"].get("max_tokens", 256))
final = None
async for out in engine.generate(job["input"]["prompt"], params, request_id=job["id"]):
final = out
return {"text": final.outputs[0].text}
apipods.serverless.start({
"handler": handler,
"concurrency_modifier": lambda current: 32,
})Dynamic concurrency
concurrency_modifier is called with the current value before the SDK fetches more jobs, so it can adapt to load, for example based on free GPU memory:
import torch
def concurrency(current: int) -> int:
free, total = torch.cuda.mem_get_info()
if free / total < 0.10:
return max(1, current - 1) # back off when memory is tight
return min(16, current + 1) # otherwise ramp up to 16
apipods.serverless.start({"handler": handler, "concurrency_modifier": concurrency})Interaction with autoscaling
The autoscaler counts job slots, not workers. With a concurrency of 8 and scalerType: REQUEST_COUNT, set scalerValue to about 8 so a new worker is added only when existing ones are full. With QUEUE_DELAY, no change is needed: jobs only wait when every slot is busy.
Choosing a value
- Diffusion models and other compute-bound work: keep 1. Running two jobs at once usually takes twice as long each.
- LLMs served by an engine with continuous batching (vLLM, SGLang): 16 to 64, depending on context length and memory.
- Handlers that mostly wait on I/O (downloads, external APIs): as high as memory allows.
- Watch
executionTimep95 on metrics while raising concurrency. Stop when it climbs faster than throughput.