Skip to content

URI bounded cache for DynamoDB account id based endpoint#6228

Closed
davidh44 wants to merge 25 commits intomasterfrom
feature/master/endpoint-id-cache-bounded
Closed

URI bounded cache for DynamoDB account id based endpoint#6228
davidh44 wants to merge 25 commits intomasterfrom
feature/master/endpoint-id-cache-bounded

Conversation

@davidh44
Copy link
Contributor

@davidh44 davidh44 commented Jul 2, 2025

Motivation and Context

Add caching for account id based endpoint in front of the URI constructors

Continuation of #6087

  • Only update is replacing LruCache with a random-eviction BoundedCache in SdkUri

Modifications

  • Added a SdkURI class which caches calls to the various URI constructors methods.
  • Added customization configuration to codegen to enable usage of SdkURI class in generated endpoint resolution code.
  • Enabled this config only for DynamoDB.

Testing

  • Unit test
  • Performance tests and profiling
  • Canary testing in progress

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

L-Applin and others added 25 commits April 25, 2025 12:56
- added codegen tests
- added equals & hash-code test for ConstructorArgs classes
- fix cache size
- SdkUri constructor
- checkstyle complained about newURI -> renamed newUri
@davidh44 davidh44 requested a review from a team as a code owner July 2, 2025 20:45
return false;
}

private void logCacheUsage(boolean containsKey, URI uri) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Was logging only useful for LRU? Can we not benefit from seeing the usage of the BoundedCache as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed previously since BoundedCache didn't have containsKey method, added method and added back logging

* Otherwise, the value is calculated based on the supplied function {@link Builder#builder(Function)}.
*/
public V get(K key) {
V value = cache.get(key);
Copy link
Contributor

Choose a reason for hiding this comment

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

can key ever be null? should we add a null check avoid cache.get(null)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, key will never be null when invoked internally by the SDK. Adding null check for future safeguard

/**
* Clean up the cache by removing an unspecified entry
*/
private void cleanup() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This cleanup implementation removes a single entry every time the cache is at capacity. That means it becomes less efficient when the cache becomes full because every new entry will follow with a cleanup() call.

Consider this:

- cache.put(key) (capacity 1)
- cache.put(key) (capacity 2)
- cache.put(key) (capacity 3)
...
...
...
- cache.put(key) (capacity 99)
- cache.put(key) (capacity 100)
- cache is at max capacity
- cleanup() removes 1
<cycle>
- cache.put(key) (capacity 99)
- cache.put(key) (capacity 100)
- cache is at max capacity
- cleanup() removes 1
- <cycle>
- cache.put(key) (capacity 99)
- cache.put(key) (capacity 100)
- cache is at max capacity
- cleanup() removes 1

Did we consider an alternative cleanup strategy?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good callout, updated to batch evict 10 entries when full

Copy link
Contributor

@RanVaknin RanVaknin left a comment

Choose a reason for hiding this comment

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

Just a few questions

@davidh44 davidh44 closed this Jul 8, 2025
@davidh44 davidh44 deleted the feature/master/endpoint-id-cache-bounded branch August 15, 2025 18:05
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.

3 participants