-
Notifications
You must be signed in to change notification settings - Fork 749
refactor(sdkv3): cache clients on creation. #6645
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
| } | ||
|
|
||
| /** | ||
| * Generalization of the {@link memoize} method that accepts async methods, and allows user to pass mapping from keys to args. |
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.
can we extend the existing memoize()? also probably want direct test coverage of this
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 was trying to maintain its type signature. Making this one return an async method would cause a lot of unrelated changes. However, no longer relevant since I refactored away from this.
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.
Making this one return an async method
would an "overload" work?
| ].join(':') | ||
| } | ||
|
|
||
| public getAwsService = memoizeWith(this.createAwsService.bind(this), this.keyAwsService.bind(this)) |
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.
memoize may not be gaining much for this use-case.
because this is an important core module, we may want more visibility into the long-lived container that stores the clients. this module could store them in a map, that could be inspected and/or logged.
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.
That makes sense, this will make it easier to add custom-logic later. Implementing it this way also makes it seem like a natural place to ensure all clients call destroy on deactivation.
e90e255 to
f44f714
Compare
|
/runIntegrationTests |
| // Serializing certain objects in the args allows us to detect when nested objects change (ex. new retry strategy, endpoints) | ||
| return [ | ||
| String(serviceOptions.serviceClient), | ||
| JSON.stringify(serviceOptions.clientOptions), |
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.
Is JSON.stringify guaranteed to return a stable ordering of keys for the same input? I think we have some "hash" code, or some other way of dealing with that, somewhere...
| return service as C | ||
| } | ||
|
|
||
| public async createAwsService<C extends AwsClient>(serviceOptions: AwsServiceOptions<C>): Promise<C> { |
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.
should the docstring call out the fact that the client will be re-used?
important for callers not to "modify" the client, except in specific "safe" ways...
is it possible that a cached client is modified such that its key no longer semantically matches its value? e.g. could its region be changed, but the "key" still has the old region?
Problem
The toolkit recreates each SDK client before each request is made. As an example see:
aws-toolkit-vscode/packages/core/src/shared/clients/ec2Client.ts
Lines 31 to 52 in b4d7417
This is done as an unnecessary guard against the client's internal state interfering with higher level business logic. Creating clients for each request is not cheap, and there is likely a better pattern to be had here.
See internal docs expanding more on this issue.
Solution
getAwsServicethat wrapscreateAwsService.ignoreCacheflag to force creation of a new client.destroyon all the clients.Testing Strategy
feature/xbranches will not be squash-merged at release time.