-
Notifications
You must be signed in to change notification settings - Fork 13
Improve NodeJS Lambda Layer cold start time #163
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
Conversation
8ecd37a
to
b5c9e6f
Compare
b5c9e6f
to
cab9e49
Compare
0512cd2
to
6df8880
Compare
6df8880
to
c6b2d64
Compare
@@ -22,7 +22,9 @@ | |||
"repository": "aws-observability/aws-otel-js-instrumentation", | |||
"scripts": { | |||
"clean": "rimraf build/*", | |||
"compile": "tsc -p .", | |||
"compile:tsc": "tsc -p .", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
who will run "compile:tsc" if we shift "compile" to "compile:webpack" as code compiling entry point?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It probably won't be run unless someone wanted to see the previous package structure.
"module": "es2020", | ||
"target": "es2020", | ||
"moduleResolution": "node", | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this the same target being used by otel lambda upstream?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, see here.
private getPropagator(): TextMapPropagator { | ||
if (process.env.OTEL_PROPAGATORS == null || process.env.OTEL_PROPAGATORS.trim() === '') { | ||
return new CompositePropagator({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a better option to not rewrite this function by copying it from upstream? can we just patch propagatorMap
for auto-configuration-propagators/utils
file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #171, we revert to using the upstream dependency
@@ -119,8 +124,8 @@ | |||
}, | |||
"files": [ | |||
"build/src/**/*.js", | |||
"build/src/**/*.js.map", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we keep the compile:tsc
command, there's no harm in keeping "build/src/**/*.js.map"
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in #171
@@ -190,6 +206,32 @@ export class AwsOpentelemetryConfigurator { | |||
return autoResource; | |||
} | |||
|
|||
private getPropagator(): TextMapPropagator { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: This can be a regular function outside of this class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed in #171
*Description of changes:* This PR is a rehash of #163 with some minor changes reverted after several autoinstrumentation package dependencies were upgraded in #168. The changes suggested by the unaddressed comments in the previous PR are addressed here. The primary change made to reduce the cold start time was to bundle the ADOT autoinstrumentation package with webpack instead of using the TS compiler. Using the same build targets as the upstream (see [this PR](https://github.com/open-telemetry/opentelemetry-lambda/pull/1679/files)), the cold start performance of the layer was improved by about 50%, from ~765ms to ~385ms. By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Description of changes:
Change 1: Using webpack to bundle the autoinstrumentation package improves tree-shaking, which significantly shortens the cold-start time for the lambda layer. Inspired by open-telemetry/opentelemetry-lambda#1679.
To test the cold-start improvement, a sample Lambda function instrumented with the Lambda layer was deployed, and a script was run which repeatedly invokes the Lambda function. The initialization time averages are then queried on Cloudwatch logs. The process is then repeated with the lambda layer removed from the Lambda function, and the times are subtracted to get the Lambda layer cold start time.
From my tests, the average cold start time for the Lambda layer improved from ~770ms to ~350ms, an almost 55% reduction. This could be further improved in the future by resolving any conflicting subdependency versions and providing more ESM compatible dependencies, which can further reduce the output bundle.
Change 2: Remove the auto-configuration-propagators dependency from autoinstrumentation package, which eliminates the B3 and Jaeger propagator transitive dependencies. This reduces the size of the zipped layer from 15MB 11.6 MB, approximately 23% decrease. Will update with performance improvements once I finish testing this change.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.