Dramatiq

Message prefetching causes worker starvation with concurrent tasks

warning
performanceUpdated Mar 7, 2019(via Exa)
Technologies:
How to detect:

When running N concurrent tasks with N workers (1 thread each), some workers prefetch and execute multiple messages sequentially while other workers remain completely idle. Default prefetch is 2 messages per worker thread. This manifests as tasks completing sequentially (1 second apart in the example) on a subset of workers instead of executing concurrently across all available workers.

Recommended action:

Ensure message prefetch count is configurable (default is 2 messages per worker thread, hardcoded in earlier versions). Fixed by making this value configurable via environment variable. When experiencing worker starvation (some workers idle while others sequentially process multiple tasks), adjust prefetch setting and monitor task distribution across workers in logs.