Skip to content

Conversation

@Will-ShaoHua
Copy link
Contributor

@Will-ShaoHua Will-ShaoHua commented Apr 22, 2025

Problem

after deployment 4/21, service has a strict 1 tps throttling policy and there was no caching for the API call previously.
It will impact users as long as they have multiple ide instances opened as all of them will make list profile call while users attempt to sign in.

Solution

  1. cache the api result for 60 seconds for reuse
  2. use lock to prevent multiple instances trying to call at the same time. Only 1 will make the service call and the rest will wait until it's done and read from the cache.

  • Treat all work as PUBLIC. Private feature/x branches will not be squash-merged at release time.
  • Your code changes must meet the guidelines in CONTRIBUTING.md.
  • License: I confirm that my contribution is made under the terms of the Apache 2.0 license.

@github-actions
Copy link

  • This pull request modifies code in src/* but no tests were added/updated.
    • Confirm whether tests should be added or ensure the PR description explains why tests are not required.

@Will-ShaoHua Will-ShaoHua marked this pull request as ready for review April 22, 2025 21:37
@Will-ShaoHua Will-ShaoHua requested review from a team as code owners April 22, 2025 21:37
@Will-ShaoHua Will-ShaoHua changed the title Profile cache feat(amazonq): Profile cache Apr 22, 2025
@Will-ShaoHua Will-ShaoHua reopened this Apr 22, 2025
@github-actions
Copy link

  • This pull request modifies code in src/* but no tests were added/updated.
    • Confirm whether tests should be added or ensure the PR description explains why tests are not required.
  • This pull request implements a feat or fix, so it must include a changelog entry (unless the fix is for an unreleased feature). Review the changelog guidelines.
    • Note: beta or "experiment" features that have active users should announce fixes in the changelog.
    • If this is not a feature or fix, use an appropriate type from the title guidelines. For example, telemetry-only changes should use the telemetry type.

@Will-ShaoHua Will-ShaoHua marked this pull request as draft April 23, 2025 08:24
@Will-ShaoHua Will-ShaoHua marked this pull request as ready for review April 23, 2025 11:04
@Will-ShaoHua Will-ShaoHua changed the title feat(amazonq): Profile cache fix(amazonq): cache listAvailableProfile result to avoid throttle Apr 23, 2025
@Will-ShaoHua Will-ShaoHua changed the title fix(amazonq): cache listAvailableProfile result to avoid throttle fix(amazonq): listAvailableProfile calls are throttled when users have 2 IDE instances and above Apr 23, 2025
@Will-ShaoHua
Copy link
Contributor Author

will add a changelog

| 'aws.toolkit.lsp.manifest'
| 'aws.amazonq.customization.overrideV2'
| 'aws.amazonq.regionProfiles'
| 'aws.amazonq.regionProfiles.cachedResult'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not set a flag on the items in aws.amazonq.regionProfiles ? why does this need an entirely separate structure?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'aws.amazonq.regionProfiles'

this is to memorize previous selected option, so we will need a separate structure to cache previous api call response

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'aws.amazonq.regionProfiles'

this is to memorize previous selected option

but that could be a flag on the item(s) in the structure. why is a separate structure needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that makes sense, i will reuse the existing one then

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@justinmk3 i encounter an issue or say concern when i am doing this exercise 3e50145#diff-f5716036a70a8b212e9dae829ec09e33731f181c173a3f2b9ad9d361d51af14bR54-R56, if I want to reuse the same global key, i might need to restructure the schema, in such case, users who already selected profile update their plugin, they might need to re-select the profile again. Given the sev2s we have right now, I am concerned if we want to do this now or is there another way to deal with such scenario?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely want to avoid a restructure. If a restructure is required, then I guess we need a new globalState field.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noted

})
}

private async tryAcquireLock(): Promise<CachedApiResultWithLock | undefined> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is rather delicate logic. And it is straightforward to generalize it. Why is it buried in a random module?

Note that

export class FileSystemState {
attempted to achieve something similiar, except using the filesystem. Though it has some known issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw Justin, i'm going to use #7151 to replace this pr for this purpose (if everything works just fine there), because the diff are pretty large so would be easier to just have another PR.

Copy link
Contributor

@justinmk3 justinmk3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although this is urgent work, it's also urgent that it works correctly. So separating it into a shared module will help with that. Especially if bugs are discovered and must be debugged.

@Will-ShaoHua Will-ShaoHua changed the title fix(amazonq): listAvailableProfile calls are throttled when users have 2 IDE instances and above fix(amazonq): listAvailableProfile calls are throttled when users have 2+ IDE instances Apr 23, 2025
@Will-ShaoHua
Copy link
Contributor Author

Will-ShaoHua commented Apr 24, 2025

replace with #7151

nkomonen-amazon pushed a commit that referenced this pull request Apr 25, 2025
…hey have 2+ vscode instances open (#7151)

## Problem
revision of #7134, this pr aims to address the comment from the previous
PR
#7134 (comment)
to extract the logic to a shared module so the diff against 7134 is
expected to be large.


after deployment 4/21, service has a strict 1 tps throttling policy and
there was no caching for the API call previously.
It will impact users as long as they have multiple ide instances opened
as all of them will make list profile call while users attempt to sign
in.

## Solution
1. cache the api result for 60 seconds for reuse 
2. use lock to prevent multiple instances trying to call at the same
time. Only 1 will make the service call and the rest will wait until
it's done and read from the cache.


---

- Treat all work as PUBLIC. Private `feature/x` branches will not be
squash-merged at release time.
- Your code changes must meet the guidelines in
[CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines).
- License: I confirm that my contribution is made under the terms of the
Apache 2.0 license.
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.

2 participants