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

Calling AmazonS3Client.GetObjectAsync() on lambda function take too long (~5s) on the first invoke #3116

Closed
hoainam1593 opened this issue Nov 30, 2023 · 6 comments
Labels
bug This issue is a bug. closed-for-staleness needs-reproduction This issue needs reproduction. perf response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. s3

Comments

@hoainam1593
Copy link

Describe the bug

I'm using S3 client in lambda function, this is my code:

public class SomeLambdaFunction
{
    public async Task<string> Handler(string input, ILambdaContext context)
    {
        var client = new AmazonS3Client();
        // begin stop watch
        await client.GetObjectAsync("<bucket-name>", "<object-key>");
        //end stopwatch and see took ~5s
    }
}

when I deploy and invoke in the first time, it took ~5s to execute client.GetObjectAsync, when I run later (reuse lambda instance), it complete instantly

Expected Behavior

AmazonS3Client.GetObjectAsync complete instantly on any invoke

Current Behavior

AmazonS3Client.GetObjectAsync take too long in the first invoke

Reproduction Steps

  • write lambda function using S3
  • call a S3 API after deploy
  • do benchmark that calling and see that calling take too long

Possible Solution

No response

Additional Information/Context

No response

AWS .NET SDK and/or Package version used

AWSSDK.S3 3.7.304.1

Targeted .NET Platform

.net 6.0

Operating System and version

lambda environment

@hoainam1593 hoainam1593 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 30, 2023
@ashishdhingra
Copy link
Contributor

@hoainam1593 Good morning. Thanks for opening the issue. The 1st invocation could take long due to Lambda cold start times, also you confirmed that the subsequent executions happen almost instantaneously. You may also try temporarily enabling verbose logging to see any SDK logic causing delay using code below:

Amazon.AWSConfigs.LoggingConfig.LogResponses = Amazon.ResponseLoggingOption.Always;
Amazon.AWSConfigs.LoggingConfig.LogTo = Amazon.LoggingOptions.Console;
Amazon.AWSConfigs.AddTraceListener("Amazon", new System.Diagnostics.ConsoleTraceListener());

Thanks,
Ashish

@ashishdhingra ashishdhingra added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. perf and removed needs-triage This issue or PR still needs to be triaged. labels Nov 30, 2023
@hoainam1593
Copy link
Author

hoainam1593 commented Dec 4, 2023

Thanks for your answer.
I'm aware of cold start issue of lambda function, but I thought it happen before lambda's handler actually run, does cold start really happen inside lambda's handler? @ashishdhingra

about the operation taking too long (~5s), it's just function to get S3 object:
await client.GetObjectAsync("", "");

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Dec 5, 2023
@ashishdhingra ashishdhingra added p1 This is a high priority issue needs-review needs-reproduction This issue needs reproduction. and removed p1 This is a high priority issue labels Dec 8, 2023
@ashishdhingra
Copy link
Contributor

@hoainam1593 Good morning. Thanks for opening the issue. The 1st invocation could take long due to Lambda cold start times, also you confirmed that the subsequent executions happen almost instantaneously. You may also try temporarily enabling verbose logging to see any SDK logic causing delay using code below:

Amazon.AWSConfigs.LoggingConfig.LogResponses = Amazon.ResponseLoggingOption.Always;
Amazon.AWSConfigs.LoggingConfig.LogTo = Amazon.LoggingOptions.Console;
Amazon.AWSConfigs.AddTraceListener("Amazon", new System.Diagnostics.ConsoleTraceListener());

Thanks, Ashish

@hoainam1593 Could you please share the Lambda memory settings as well?

@ashishdhingra ashishdhingra added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-review labels Dec 8, 2023
@hoainam1593
Copy link
Author

I used the lowest one 128MB

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Dec 12, 2023
@ashishdhingra
Copy link
Contributor

@hoainam1593 We recently pushed a new version AWSSDK.Core version 3.7.300.18 that contained fix for performance degradation reported as part of another issue. Could you please check if upgrading to this version (or later) fixes your issue?

Thanks,
Ashish

@ashishdhingra ashishdhingra added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Dec 14, 2023
Copy link

This issue has not received a response in 5 days. If you want to keep this issue open, please just leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. closed-for-staleness needs-reproduction This issue needs reproduction. perf response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. s3
Projects
None yet
Development

No branches or pull requests

2 participants