Skip to content

[BUG]: DD_PROFILING_MEMORY_ENABLED=true slows down application significantly #13307

@bmalehorn

Description

@bmalehorn

Tracer Version(s)

ddtrace 3.6.0

Python Version(s)

Python 3.10.6

Pip Version(s)

pip 22.3.1

Bug Report

Hello,

We've noticed a significant slowdown in one of our applications in production that seems to be related to memory size.

This application pulls in quite a lot of data, and stores it all in memory. Specifically it fetches about 1 million rows of a table, in batches of 10k at a time, and stores them as ORM objects in a big list. Additionally the slowdown increases over time, with the queries starting out fairly fast, but each query gets slower and slower over time.

I reproduced this in my local environment and ultimately made a 5x speedup by disabling the memory profiler via DD_PROFILING_MEMORY_ENABLED=false - see below for some evidence.

Discussed on the public Datadog Slack here: https://datadoghq.slack.com/archives/C0633E2KH16/p1746038872275079 and in a private message with @taegyunkim.

Org id: 550746 (Lumos)

Reproduction Code

I have a reproduction in my local environment. With memory profiling turned off:

env | grep DD_PROFILING
DD_PROFILING_MEMORY_ENABLED=false
DD_PROFILING_ENABLE_CODE_PROVENANCE=true
DD_PROFILING_ENABLED=true
DD_PROFILING_STACK_V2_ENABLED=true
DD_PROFILING_MAX_FRAMES=256

cd /workflows && ENVIRONMENT=LOCAL /usr/local/bin/pip show ddtrace
Name: ddtrace
Version: 3.6.0

I log how long each batch takes, and each batch runs fairly quickly:

...
elapsed=0.426
elapsed=0.197
elapsed=0.224
...

total time to load 1009015 rows: 108 seconds

When I run with memory profiling enabled:

env | grep DD_PROFILING
DD_PROFILING_MEMORY_ENABLED=true
DD_PROFILING_ENABLE_CODE_PROVENANCE=true
DD_PROFILING_ENABLED=true
DD_PROFILING_STACK_V2_ENABLED=true
DD_PROFILING_MAX_FRAMES=256

cd /workflows && ENVIRONMENT=LOCAL /usr/local/bin/pip show ddtrace
Name: ddtrace
Version: 3.6.0

Running the job, it starts out fast:

21:44:56.047: elapsed=0.256
21:44:56.368: elapsed=0.134
21:44:56.725: elapsed=0.175
...

but after running for several minutes, it's quite slow, and getting slower over time:

21:48:05.580: elapsed=4.788
21:48:14.728: elapsed=5.256
21:48:23.544: elapsed=4.784

total time to load 1009015 rows: 507 seconds

Error Logs

Here are some relevant links for myself & others:

Libraries in Use

Relevant libraries used in this reproduction:

SQLAlchemy==1.3.16
mysqlclient==2.2.7
ddtrace==3.6.0

Operating System

Linux 8ea13d816b46 6.10.14-linuxkit #1 SMP Fri Nov 29 17:22:03 UTC 2024 aarch64 GNU/Linux

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions