-
-
Notifications
You must be signed in to change notification settings - Fork 350
Description
Type: Feature
SimpleMessageListenerContainer's concurrency model is suboptimal. Current behavior:
- Request N messages from SQS (N <= 10 due to AWS restriction).
- Create a MessageExecutor for each message and execute concurrently.
- Wait for ALL N messages to be handled (including possible SQS deletion invocations).
- Repeat
Problems:
- No message handling occurs while fetching messages from SQS. This could be a significant fraction of time for messages that can be handled quickly.
- Request cycle time is constrained by the most slowly handled message in the batch of N. For example, if one message in a batch of N takes 10 seconds to handle and the rest only take one second, throughput will be only N/10 per second (presuming default executor thread pool sizing).
- No ability to process more than 10 messages concurrently due to AWS restriction on max batch size.
Proposed solution:
Continue to use a spinning thread to retrieve messages from SQS. However, instead of waiting for all messages to be processed before requesting another batch, rely on the executor to enforce the desired level of parallelism and locally queued messages (via its own work queue). The spinning thread should block on the executor queue's ability to enqueue additional work. This would allow for efficient parallel processing wider than 10.
Work-around:
I did essentially the above by implementing @SqsListener
methods that attempt to hand-off messages to another executor pool and retry until the pool accepts the work. This works, but it (a) adds complexity and (b) requires manual acknowledgment handling.
It would be a better developer experience if one could simply specify the number of messages to fetch at once, the max number to process at once, and how many messages should be retrieved ahead of processing availability.
Note:
Even with my work-around, I've been unable to keep a large number of worker threads busy when servicing a queue with messages that are quick to process. The single thread fetching messages from the queue is the limiting factor. An additional enhancement is to allow N message retrieval threads.