Skip to content
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

feat(util-endpoint): add endpoint ruleset cache #1385

Merged
merged 4 commits into from
Sep 6, 2024

Conversation

kuhe
Copy link
Contributor

@kuhe kuhe commented Sep 2, 2024

aws/aws-sdk-js-v3#6423

This PR creates a cache for endpoint ruleset resolution.

As one would expect, the input and cache key are the endpoint params and the output and cache value is the endpoint.

Some services declare endpoint parameters in excess of what is actually evaluated in the ruleset, so codegen provides the explicit pared param list to the cache instance.

  • codegen to connect EndpointCache to the service's endpointResolver.ts file contents.
  • codegen to determine what the pared parameter list is to avoid cache pollution from irrelevant params

@kuhe kuhe requested review from a team as code owners September 2, 2024 19:16
@kuhe kuhe requested a review from milesziemer September 2, 2024 19:16
@kuhe kuhe marked this pull request as draft September 2, 2024 19:32
@kuhe kuhe force-pushed the feat/endpoint-cache branch 2 times, most recently from 49365a0 to 389ead3 Compare September 3, 2024 18:17
@kuhe kuhe marked this pull request as ready for review September 3, 2024 18:18
@kuhe
Copy link
Contributor Author

kuhe commented Sep 3, 2024

The S3 resolver would now look like this below.
Notably absent is Key from the parameter list.

// smithy-typescript generated code
import { awsEndpointFunctions } from "@aws-sdk/util-endpoints";
import { EndpointV2, Logger } from "@smithy/types";
import { customEndpointFunctions, EndpointCache, EndpointParams, resolveEndpoint } from "@smithy/util-endpoints";

import { EndpointParameters } from "./EndpointParameters";
import { ruleSet } from "./ruleset";

const cache = new EndpointCache({
  size: 50,
  params: [
    "Accelerate",
    "Bucket",
    "DisableAccessPoints",
    "DisableMultiRegionAccessPoints",
    "DisableS3ExpressSessionAuth",
    "Endpoint",
    "ForcePathStyle",
    "Region",
    "UseArnRegion",
    "UseDualStack",
    "UseFIPS",
    "UseGlobalEndpoint",
    "UseObjectLambdaEndpoint",
    "UseS3ExpressControlEndpoint",
  ],
});

export const defaultEndpointResolver = (
  endpointParams: EndpointParameters,
  context: { logger?: Logger } = {}
): EndpointV2 => {
  return cache.get(endpointParams as EndpointParams, () =>
    resolveEndpoint(ruleSet, {
      endpointParams: endpointParams as EndpointParams,
      logger: context.logger,
    })
  );
};

customEndpointFunctions.aws = awsEndpointFunctions;

@kuhe
Copy link
Contributor Author

kuhe commented Sep 3, 2024

In one benchmark, a batch of 10 parallel Amazon S3 HeadObject requests completed in 80ms, as opposed to 86ms without this cache.

@kuhe kuhe force-pushed the feat/endpoint-cache branch 2 times, most recently from 1f511f3 to f97331f Compare September 3, 2024 19:52
@kuhe kuhe force-pushed the feat/endpoint-cache branch 2 times, most recently from 73e7555 to 4295b21 Compare September 5, 2024 15:52
@kuhe kuhe force-pushed the feat/endpoint-cache branch from 9a72403 to a33c22a Compare September 5, 2024 20:02
@kuhe kuhe merged commit 1ff575c into smithy-lang:main Sep 6, 2024
11 checks passed
@kuhe kuhe deleted the feat/endpoint-cache branch September 6, 2024 15:25
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