-
Notifications
You must be signed in to change notification settings - Fork 459
Description
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:
- datadog: prod profile
- datadog: my run with DD_PROFILING_MEMORY_ENABLED=false individual profile
- datadog: my run with DD_PROFILING_MEMORY_ENABLED=true individual profile
- [personal] my run with DD_PROFILING_MEMORY_ENABLED=false: http://localhost:8082/runs/8206e632-db85-463a-8662-34e464fa1198
- [personal] my run with DD_PROFILING_MEMORY_ENABLED=true: http://localhost:8082/runs/cf9638f7-0c02-4591-a636-c19fb53e91f0
- [personal] my branch upgrading to 3.6.0:
brian/profiler-perf-all-ddtrace-3.6.0
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