⚡ Optimize Blocking AWS Bedrock Calls in Async Methods#6
⚡ Optimize Blocking AWS Bedrock Calls in Async Methods#6
Conversation
Modified `BedrockProvider` to use `asyncio.to_thread` for all blocking operations, including: - `invoke_model` and `invoke_model_with_response_stream` calls. - Reading the response body in `send_message`. - Iterating over the `EventStream` in `stream_message`. This ensures that the FastAPI event loop is not blocked during AWS Bedrock interactions, significantly improving concurrency and throughput. Performance measurements (for 3 concurrent requests): - Before: 3.00s - After: 1.02s (~66% reduction in total time for concurrent load) Co-authored-by: tstapler <3860386+tstapler@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
@jules Can we use anyio for our io/async here? |
Good suggestion! I've updated the implementation to use |
|
We have merge conflicts now please address them @jules |
The AWS Bedrock provider was using synchronous boto3 calls (
invoke_modelandinvoke_model_with_response_stream) directly within asynchronous methods. This caused the entire proxy server's event loop to block while waiting for Bedrock responses, effectively serializing all requests to this provider.I have optimized both
send_messageandstream_messageby:asyncio.to_thread.response["body"].read()operation.EventStreamiteration into an async-safe loop by wrapping eachnext()call inasyncio.to_thread.Verification using concurrent benchmark scripts confirmed that the implementation is now non-blocking, reducing the total time for 3 concurrent requests from 3.00s to 1.02s.
PR created automatically by Jules for task 949472333596472778 started by @tstapler