title: Control Queue Concurrency impact: HIGH impactDescription: Prevents resource exhaustion with concurrent limits tags: queue, concurrency, worker_concurrency, limits
Control Queue Concurrency
Queues support worker-level and global concurrency limits to prevent resource exhaustion.
Incorrect (no concurrency control):
DBOS.register_queue("heavy_tasks") # No limits - could exhaust memory
@DBOS.workflow()
def memory_intensive_task(data):
# Uses lots of memory
pass
Correct (worker concurrency):
# Each process runs at most 5 tasks from this queue
DBOS.register_queue("heavy_tasks", worker_concurrency=5) # after DBOS.launch()
@DBOS.workflow()
def memory_intensive_task(data):
pass
Correct (global concurrency):
# At most 10 tasks run across ALL processes
DBOS.register_queue("limited_tasks", global_concurrency=10) # after DBOS.launch()
In-order processing (sequential):
# Only one task at a time - guarantees order
DBOS.register_queue("sequential_queue", global_concurrency=1) # after DBOS.launch()
@DBOS.step()
def process_event(event):
pass
def handle_event(event):
DBOS.enqueue_workflow("sequential_queue", process_event, event)
Worker concurrency is recommended for most use cases. Global concurrency should be used carefully as pending workflows count toward the limit (including workflows from previous application versions).
The global limit parameter is global_concurrency. worker_concurrency must be <= global_concurrency. For per-user/per-tenant limits, see queue-partitioning.
Reconfiguring at Runtime
Because queue configuration lives in the system database, you can change a queue’s concurrency at runtime without redeploying. Workers pick up the new configuration on their next polling iteration.
queue = DBOS.retrieve_queue("heavy_tasks")
queue.set_global_concurrency(20)
queue.set_worker_concurrency(2)
In async code, use the _async variants (set_global_concurrency_async, set_worker_concurrency_async) to avoid blocking the event loop.
If your application also calls DBOS.register_queue on startup, the next process to launch can overwrite your runtime changes. Either update the register_queue call to match, or pass on_conflict="never_update" to preserve runtime values.
Reference: Managing Concurrency