-
Notifications
You must be signed in to change notification settings - Fork 25.4k
Fixing bug with bedrock client caching #118177
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
Conversation
Hi @ymao1, I've created a changelog YAML for you. |
Pinging @elastic/ml-core (Team:ML) |
docs/changelog/118177.yaml
Outdated
@@ -0,0 +1,6 @@ | |||
pr: 118177 | |||
summary: Fixing bug with bedrock client caching |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something like: Fixing bedrock event executor terminated cache issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in 5882aa4
builtClient.resetExpiration(); | ||
return builtClient; | ||
return clientsCache.compute(modelHash, (hashKey, client) -> { | ||
if (client == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think we could collapse this to something like:
AmazonBedrockBaseClient clientToUse = client;
if (clientToUse == null) {
clientToUse = creator.apply(model, timeout);
}
clientToUse.setClock(clock);
clientToUse.resetExpiration();
return clientToUse;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in 5882aa4
return builtClient; | ||
} else { | ||
// for testing | ||
client.setClock(clock); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: This is completely unrelated to your PR but I wonder if we could refactor the client class' creator function to take the clock as a parameter so we can avoid the setClock()
class here 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not tackle this comment in this PR but I left a code comment. Would you like me to open an issue?
💚 Backport successful
|
* Fixing bug with bedrock client caching * Update docs/changelog/118177.yaml * PR feedback
* Fixing bug with bedrock client caching * Update docs/changelog/118177.yaml * PR feedback
Resolves #117916
Summary
Fixes an order of operations bug with flushing the client cache and retrieving the client. Previously, we look in the cache for a client and return it, regardless of whether it is expired or not, and then we flush the cache of expired clients. This was causing the
event executor terminated
error. This PR changes the order so that we flush the cache of expired clients first and then we try to retrieve the client (creating a new one if the expired one was flushed).Updates the expiration date of the client if the client is used. This allows an actively used client to continue being cached. Previously, the client would be flushed every 5 minutes regardless of whether it's in use or not. If this is not the desired behavior, I can revert this change.