Repository navigation
Reuse one Bedrock client for a pipeline's requests - #6222
Open
yuki-uchida wants to merge 1 commit into
Open
yuki-uchida wants to merge 1 commit into
yuki-uchida wants to merge 1 commit into
Conversation
yuki-uchida
force-pushed
the
bedrock-reuse-client
branch
from
October 18, 2026 05:04
0cd4167 to
d3b0713
Compare
AWSBedrockLLMService opens its aiobotocore client in setup() and closes it in cleanup(), so the requests of a running pipeline share one connection pool. A service that is never set up, such as one only called through run_inference() by a classifier, creates a client per request, since nothing would close a kept one. A response stream cut short by an interruption is closed so its connection is not left half-read in the pool. A new client per request costs a TCP and TLS handshake on every turn; from Tokyo that is about 0.4 s of time to first token on us-east-1. The default config keeps idle connections for an hour, since aiobotocore's 12 s default is shorter than the gap between turns.
yuki-uchida
force-pushed
the
bedrock-reuse-client
branch
from
October 18, 2026 07:22
d3b0713 to
d4e0222
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please describe the changes in your PR. If it is addressing an issue, please reference that as well.
What Changed
Reuse the Bedrock client across a pipeline's requests, so each turn skips a new TCP + TLS connection and reaches the first token sooner.
Performance Result
Median TTFT from Tokyo over six runs, shared vs. per-request client:
us-east-1549 vs. 994 ms,us-west-2466 vs. 822 ms,ap-northeast-1793 vs. 911 ms.Notice
setup()and closed incleanup(). A service that is never set up (e.g. one used only byLLMClassifierthroughrun_inference()) still gets a client per request, since nothing would close a kept one. An interrupted response stream is closed so the shared client's pool keeps no half-read connection.keepalive_timeout=3600), since aiobotocore's 12 s default is shorter than the gap between turns.Test Case
Tests cover a client per request before
setup(), one shared client after it, and a successful request after an interrupted stream.