Skip to content

Reuse one Bedrock client for a pipeline's requests - #6222

Open
yuki-uchida wants to merge 1 commit into
pipecat-ai:mainfrom
yuki-uchida:bedrock-reuse-client
Open

yuki-uchida wants to merge 1 commit into
pipecat-ai:mainfrom
yuki-uchida:bedrock-reuse-client

Conversation

@yuki-uchida

@yuki-uchida yuki-uchida commented Oct 18, 2026 •

Copy link
Copy Markdown

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-1 549 vs. 994 ms, us-west-2 466 vs. 822 ms, ap-northeast-1 793 vs. 911 ms.

Notice

  • mechanism
    • The client is opened in setup() and closed in cleanup(). A service that is never set up (e.g. one used only by LLMClassifier through run_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
    • The default config keeps idle connections for an hour (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.

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant