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

Slow Initialization Time for Sentry SDK in AWS Lambda #3763

Closed
kalyan-koneru opened this issue Nov 11, 2024 · 4 comments
Closed

Slow Initialization Time for Sentry SDK in AWS Lambda #3763

kalyan-koneru opened this issue Nov 11, 2024 · 4 comments

Comments

@kalyan-koneru
Copy link

How do you use Sentry?

Sentry Saas (sentry.io)

Version

2.18.0

Steps to Reproduce

While implementing a simple AWS Lambda function, I observed significant delays related to Sentry SDK initialization. Specifically:

  1. import sentry_sdk takes approximately ~ 300 ms.
  2. sentry_sdk.init takes an additional 25SampleSentrySdkFunction.zip
    0 ms.

These delays contribute to an increased cold start time for AWS Lambda functions, which could impact performance in latency-sensitive applications.

I have attached the lambda function I used to test the performance

Expected Result

Expect the sentry initialization time to be under 50ms

Actual Result

Sentry initialization time is over 500ms

Elapsed time import sentry_sdk: 304 ms
Elapsed time sentry_sdk.init: 257 ms

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Nov 11, 2024
@szokeasaurusrex
Copy link
Member

szokeasaurusrex commented Nov 12, 2024

@kalyan-koneru thank you for the feedback.

First of all, when measuring the time it takes for the Sentry SDK to initialize, you should use time.process_time_ns() rather than time.time().

The problem with time.time() is that it measures the entire elapsed time of the SDK's initialization, including time where the process initializing the Sentry SDK is sleeping. On the other hand, time.process_time_ns() excludes time when the process is sleeping. So, time.process_time_ns() will give you a more accurate idea of how much time it actually takes the Sentry SDK to initialize.

I don't find it that surprising though that there is some delay to initializing the Sentry SDK. We need to do quite a bit of work to instrument your application properly with the SDK, so it is no surprise that this does add a delay.

Did you notice a sudden performance regression from a previous version of the Sentry SDK, or has it always been like this for you?

@kalyan-koneru
Copy link
Author

@szokeasaurusrex

Thank you for the clarification on using time.process_time_ns() to measure initialization time more accurately. We were indeed using time.time() and will switch to time.process_time_ns() to get a clearer view of the SDK's active processing time.

Regarding performance, we haven't specifically checked for regressions in the current version of the Sentry SDK. This issue came to our attention while investigating cold startup times in our Python application, where we observed the Sentry SDK initialization taking around 500ms. Do you consider this a reasonable performance expectation, or are there optimizations we could look into?

@getsantry getsantry bot moved this from Waiting for: Community to Waiting for: Product Owner in GitHub Issues with 👀 3 Nov 12, 2024
@szokeasaurusrex
Copy link
Member

@kalyan-koneru Could you first try timing the import and initialization with time.process_time_ns()?

It's hard to tell whether a 500ms duration measured with time.time() is reasonable because the duration with time.time() depends on many external factors that are specific to your system, and which could even vary between individual runs of the program.

@getsantry
Copy link

getsantry bot commented Dec 6, 2024

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you remove the label Waiting for: Community, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@getsantry getsantry bot added the Stale label Dec 6, 2024
@getsantry getsantry bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

3 participants