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

Minor performance improvements to Amazon.Lambda.RuntimeSupport #1063

Merged
merged 1 commit into from
Feb 2, 2022

Conversation

normj
Copy link
Member

@normj normj commented Feb 1, 2022

Description of changes:

Minor tweaks while profiling Amazon.Lambda.RuntimeSupport to reduce time spent in this package during coldstarts. I would have liked to do more style/whitespace cleanup to InternalClientAdapted but I don't want the logic changes to be unnoticeable in a file with all lines changed.

  • Added additional internal logging statements to help with understanding where time is being spent. These logging statements are a noop unless the LAMBDA_RUNTIMESUPPORT_DEBUG environment variable is set.
  • Changes in InternalClientAdapted
    • Use source generator JSON serialization when targeting .NET 6
    • Remove code treating HTTP status code as strings
    • Skipped deserialize response when sending response since all we need is the HTTP status code
    • Got rid of the Error2Async method since this was replaced in previous PR with ErrorWithXRayCauseAsync
    • Consolidated the InternalClientAdapted.cs and InternalClientAdapted.custom.cs since are not longer depending on this file being generated.
  • Added AWS_LAMBDA_DOTNET_DEBUG_RUN_ONCE environment variable for local profiling so process terminates cleanly after processing a single event. This environment variable should never be set when deployed to Lambda.
  • For .NET 6 directly create the SocketsHttpHandler for the HttpClient to avoid the HttpClient creating an additional wrapper handler HttpClientHandler.
  • Remove lingering ties to NSwag generator since we have customized InternalClientAdapted.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@normj normj requested a review from ganeshnj February 1, 2022 01:40
@normj normj force-pushed the norm/perf-work-lambdabootstrap branch from 1486703 to ed2f8e2 Compare February 1, 2022 01:42
bool doStartInvokeLoop = _initializer == null || await InitializeAsync();

while (doStartInvokeLoop && !cancellationToken.IsCancellationRequested)
{
try
{
await InvokeOnceAsync(cancellationToken);
if(runOnce)
{
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should do some logging that Lambda is configured for run once and process is exiting for diagnostics.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea, I have added the messaging.

@normj normj force-pushed the norm/perf-work-lambdabootstrap branch from ed2f8e2 to 80eefeb Compare February 1, 2022 01:56
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.

None yet

3 participants