Skip to content

[Serverless] Lazy-load datadog/api to speed up the cold start#684

Closed
maxday wants to merge 3 commits into
masterfrom
maxday/lazy-load-api
Closed

[Serverless] Lazy-load datadog/api to speed up the cold start#684
maxday wants to merge 3 commits into
masterfrom
maxday/lazy-load-api

Conversation

@maxday
Copy link
Copy Markdown

@maxday maxday commented Aug 27, 2021

What does this PR do?

This PR lazy-loads the datadog/api package.
This package is quite heavy (mainly due to http_client) and slows down cold starts in AWS Lambda environment.
Here is the flamegraph showing the size of datadog/api (in purple)

Screen Shot 2021-08-27 at 10 47 29 AM

We have already refactored our datadog/api in the Lambda Library here : DataDog/datadog-lambda-python#163

Description of the Change

Lazy-load the datadog/api package + unit testing

Alternate Designs

As we use this package in datadog-lambda-python the change needs to be at this deeper level

Verification Process

New flamegraph does NOT show any calls to datadog/api

Review checklist (to be filled by reviewers)

  • Feature or bug fix MUST have appropriate tests (unit, integration, etc...)
  • PR title must be written as a CHANGELOG entry (see why)
  • Files changes must correspond to the primary purpose of the PR as described in the title (small unrelated changes should have their own PR)
  • PR must have one changelog/ label attached. If applicable it should have the backward-incompatible label attached.
  • PR should not have do-not-merge/ label attached.
  • If Applicable, issue must have kind/ and severity/ labels attached at least.

@maxday maxday requested review from a team as code owners August 27, 2021 18:54
Comment thread datadog/__init__.py

# If we are in an AWS Lambda environment we can skip loading and configuration api
# as underlying packages are heavy to load and slows down cold start
if os.environ.get("AWS_LAMBDA_FUNCTION_NAME") is None:
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I was thinking about a double check with the presence of /opt/datadog-agent But this file is only loaded when the extension is here (https://github.com/DataDog/datadog-lambda-python/blob/main/datadog_lambda/metric.py#L22)

@maxday maxday closed this Aug 27, 2021
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.

1 participant