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(middleware-user-agent): cache user agent string #3970

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Commits on May 15, 2024

  1. feat(middleware-user-agent): cache user agent string

    Cache the user agent string after the first successful computation.
    Do this in a way that ensures `await` isn't called in the middleware if
    the user agent is already computed (run middleware in single tick).
    
    Middleware such as the user agent is called on every single call to aws,
    so for dbs (e.g. fetching single keys), the middleware should in
    principle be memory/cpu efficient.
    
    Context: I saw that client-dynamodb calls took twice as long to resolve,
    and cpu usage was slightly higher after switching from aws-sdk,
    even after the fix for 2223. The impact on dynamodb promise resolution
    times was higher at peak load when Node.js was using more cpu per process.
    (The Node.js process had around 40% cpu usage)
    - I'm not completely certain this is the cause, but it seems related.
      There's extra function calls, map, array creation/join, and
      string escaping.
      Additionally, the call to await() would spread out the work of
      creating the user agent across multiple CPU ticks.
    - (Related to 2027 which was fixed by memoizing in the implementation of
      defaultUserAgentProvider)
    
    Avoid extra cpu from calling map, defaultUserAgentProvider+await, etc.
    
    As a result of 388b180 switching from
    defaultUserAgent to defaultUserAgentProvider, the middleware would have
    to recompute the user agent on every single api call. This fixes that by
    computing the user agent only once, when the middleware is instantiated.
    (So creating a client but not using it will now call this, but creating
    a client has overhead anyway)
    TysonAndre committed May 15, 2024
    Configuration menu
    Copy the full SHA
    84e13eb View commit details
    Browse the repository at this point in the history