Prefetch count (QoS setting) giới hạn số message chưa ack mà RabbitMQ gửi cho consumer cùng lúc — nếu prefetch là 1, broker chờ ack trước khi gửi message tiếp.
- Prefetch cao (ví dụ 1000) cho throughput nhanh hơn nhưng tốn bộ nhớ và rủi ro mất nhiều message nếu consumer crash.
- Prefetch thấp (1) an toàn hơn, phân phối đều hơn nhưng latency cao hơn.
- Best practice: prefetch = số thread worker trong consumer (ví dụ prefetch 10 cho 10 thread), cân bằng giữa throughput và safety.
Prefetch count (QoS) limits how many unacknowledged messages RabbitMQ sends to a consumer at once — prefetch of 1 means the broker waits for an ack before sending the next.
High prefetch
- gives faster throughput but higher memory use and crash risk. Low prefetch
- is safer with more even distribution but higher latency
Best practice: prefetch = number of worker threads.