Skip to content

URI cache for DynamoDB account id based endpoint #6087

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

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

L-Applin
Copy link
Contributor

@L-Applin L-Applin commented May 5, 2025

Motivation and Context

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

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

Types of changes

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

@L-Applin L-Applin marked this pull request as ready for review May 6, 2025 15:24
@L-Applin L-Applin requested a review from a team as a code owner May 6, 2025 15:24
@@ -168,6 +168,10 @@ public int size() {
return cache.size();
}

public boolean contains(K key) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: containsKey?

private final LruCache<UriConstructorArgs, URI> cache = LruCache.builder(UriConstructorArgs::newInstance)
.maxSize(100)
.build();

Copy link
Contributor

Choose a reason for hiding this comment

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

Missing private ctor?

private static final SdkUri INSTANCE = new SdkUri();

private final LruCache<UriConstructorArgs, URI> cache = LruCache.builder(UriConstructorArgs::newInstance)
.maxSize(100)
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought 150 is what we decided. Can we create a constant and add a comment explaining why this magic number was chosen

}

private void logCacheUsage(boolean containsKey, URI uri) {
if (log.isLoggingLevelEnabled(Level.TRACE)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

log.isLoggingLevelEnabled is not required for SdkLogger

StringConstructorArgs key = new StringConstructorArgs(s);
boolean containsK = cache.contains(key);
URI uri = cache.get(key);
logCacheUsage(containsK, uri);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we do cache.contains check in logCacheUsage?

}

@Override
public int hashCode() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add tests for equals and hashcode for all of them?


private static final SdkUri INSTANCE = new SdkUri();

private final LruCache<UriConstructorArgs, URI> cache = LruCache.builder(UriConstructorArgs::newInstance)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we initialize it in SdkUri ctor? On a similar note, worth doing lazy initialization for SdkUri singleton? Note that we can use Lazy

@@ -274,7 +278,11 @@ private void codegenTreeBody(RuleSetExpression expr) {
@Override
public Void visitEndpointExpression(EndpointExpression e) {
builder.add("return $T.endpoint(", typeMirror.rulesResult().type());
builder.add("$T.builder().url($T.create(", Endpoint.class, URI.class);
if (endpointCaching) {
builder.add("$T.builder().url($T.getInstance().create(", Endpoint.class, SdkUri.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a codegen tests?

Actually, should we just do it for all service clients at this point? I don't really see us removing the logic ever...

"type": "feature",
"category": "AWS SDK for Java v2",
"contributor": "",
"description": "URI cache for DynamoDB account id based endpoint"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we describe the behavior rather than implementation?

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