-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: handle batch messages in parallel in batch module #1540
Comments
Initial thoughts -
It's a cool idea though! Especially where we are fanning out to do downstream IO it should make a substantial difference to runtime and be a nice cost optimization for users. |
I don't understand... If we use
Not logging, serialization module with |
I just wanted to Chime in add my support for this. We use Kotlin and having some kind of Async interface (which I believe exists in the Python library?) would be really cool to have, performance wise. Especially if it's a case where a Lambda pulls messages from a queue just to make a DDB call, or something like that. |
Hi @itsmichaelwang, thanks for your comment. I'm not super familiar with Kotlin, but if you could share the kind of signature you expect, it would help. We probably won't make public an async interface (with java Future), and will handle it internally, but happy to discuss this... |
You need a ThreadPool, but I don't think you shouldn't have to create a new one but rather use thread pools the runtime provides and manages. It looks like we should use
MDC uses thread local - isn't this a problem?
👍 |
From the last article:
We don't really know what users will do (CPU-intensive or not). Maybe
Yes, you're right, MDC uses ThreadLocal. The way we handle powertools fields today is based on MDC so it could be yes... We probably would need to pass the MDC context map to the threads in order to fill their own version of it... We should first try to find the best way to implement parallelism (
|
It's actually much simpler with parallel: List<SQSBatchResponse.BatchItemFailure> batchItemFailures = event.getRecords()
.parallelStream()
.map(sqsMessage -> processTheMessageAndReturnOptionalOfBatchItemFailure(sqsMessage, context))
.filter(Optional::isPresent)
.map(Optional::get)
.collect(Collectors.toList()); Note that in both case I don't handle the FIFO |
Parallel streams! That looks exactly like what we want. I think this comment you made is why - we pick a level of abstraction where we're letting java handle the actual implementation of the parallelization:
One question that nags a bit - do we want the user to be able to return a future in their
|
+1 for this feature request. This would be amazing to have. I was trying to implement a parallizable implementation of the batch processor because the synchronous version is too slow for my needs but managing work such as removing successes from the SQS, removing retryable failures after pushing to the dlq, handing num retries before failure, etc that we all get for free via powertools is a lot of work and non-trivial. Having async processing support officially would be amazing. |
I think we should prioritize this for v2 @jeromevdl . What do you think? |
When is v2 set for if this is in scope for v2? |
Hey @kyuseoahn , we're targeting first half 2024 for this at the moment! |
Is your feature request related to a problem? Please describe.
At the moment, the batch module processes messages in sequence (code), which could be improved with a parallel processing for better performance.
Describe the solution you'd like
BatchMessageHandler
could provide aprocessBatchInParallel
method with the same signature asprocessBatch
but with a different behaviour (parallel processing instead of serial)CompletableFuture
. It would be something like this (probably not that easy but that's a start):Describe alternatives you've considered
streams provide a
parallel
method which is based on the number of vCPUs (Runtime.getRuntime().availableProcessors()
). UsingCompletableFuture
, we can define the number of executors, potentially more than the number of vCPUs. We should probably perform some load tests on Lambda to check if that's actually better, because parallel is probably much easier to implement.Additional context
The text was updated successfully, but these errors were encountered: