Closed dmarkey closed 3 years ago
@dmarkey I am having some trouble replicating this issue:
I am just doing:
# run.py
import timeit
import pymongo
def test():
client = pymongo.MongoClient()
assert client.server_info()
t = timeit.Timer(test)
results = t.repeat(200, 1)
print(f"min: {min(results)}")
print(f"max: {max(results)}")
print(f"avg: {sum(results) / len(results)}")
and then:
$ ddtrace-run python run.py
min: 0.0066359740000000444
max: 0.03534934000000001
avg: 0.007919707545000005
Even with patching disabled the numbers are basically the same. Same for if I do ddtrace.patch_all()
instead of ddtrace-run
.
I mostly wanted to quickly check and see if there was anything obvious that is causing one specific connection to take longer than others.
Is there any further information you can provide to help me replicate the issue?
Does the issue occur only when using uWSGI? If so, would you be able to share your uWSGI configuration with me?
Do you have specific connection setup that I should try to replicate?
What version of Python are you using?
What version of Mongo are you using?
I think i've seen the issue also occurring using manage.py runserver
but here is the uwsgi configuration anyway.
[uwsgi]
plugins = python3
need-app = True
uid = django
gid = django
log-5xx = true
disable-logging = true
enable-threads = True
workers = 3
harakiri = 55
# Enforce limits to requests to avoid memory leaks
max-requests = 5000
max-requests-delta = 1000
wsgi-disable-file-wrapper = true
vacuum = True
chdir = /opt/app/src
env = DJANGO_SETTINGS_MODULE=project.docker_settings
env = prometheus_multiproc_dir=/tmp/metrics/
manage-script-name = true
mount = /=project.wsgi:application
# the socket
socket = 127.0.0.1:8001
reload-on-as = 768
reload-on-rss = 256
harakiri-verbose = true
reload-mercy = 300
lazy-apps=true
# Export uWSGI stats
stats=127.0.0.1:1717
safe-pidfile=/opt/app/uwsgi.pid
lazy_apps=true
may be important here.
alpine:3.10
Python 3.7.10 (default, Mar 2 2021, 09:06:08)
Other things of note
patch_all()
is happening early in app initialisation (at the start of the wsgi file)
We have the following in the docker_settings.py file to initialise the connection to mongoengine:
from mongoengine import connect
connect(MONGODB_DATABASE, host=MONGODB_SERVER, port=MONGODB_PORT, connect=False)
This was the exact code path that was slowing down(it's simply to check connectivity - wrapped in a simple view):
conn = mongoengine.connect(
settings.MONGODB_DATABASE,
host=settings.MONGODB_SERVER,
port=settings.MONGODB_PORT, connect=True)
conn.admin.command('ismaster')
conn.close()
Using this mongodb image:
mvertes/alpine-mongo:3.4.9-0
Hope this helps!
Thanks! This is great. It might take me a minute to reproduce, but I'll let you know if I need anything else!
oh wow... yup... definitely can confirm this
$ ddtrace-run python run.py
count: 25
min: 0.013789596000000015
p50: 0.5316218780000002
p75: 4.768647105
p95: 173.10879761329997
max: 204.309137153
Here are the results running with the patching disabled:
$ DD_TRACE_MONGOENGINE_ENABLED=false DD_TRACE_PYMONGO_ENABLED=false ddtrace-run python run.py
count: 25
min: 0.012196068000000004
p50: 0.5111844989999987
p75: 0.5154976094999997
p95: 0.5215658128000004
max: 0.5227140460000008
# run.py
import statistics
import timeit
import ddtrace
ddtrace.patch_all()
from mongoengine import connect
def test():
client = connect(connect=False)
client.admin.command("ismaster")
client.close()
t = timeit.Timer(test)
results = t.repeat(25, 1)
p = statistics.quantiles(results, n=100)
print(f"count: {len(results)}")
print(f"min: {min(results)}")
print(f"p50: {p[49]}")
print(f"p75: {p[74]}")
print(f"p95: {p[94]}")
print(f"max: {max(results)}")
I do not have a great sense of why this is happening, but I was able to reproduce. Next steps we'll need to dig into this further.
Great that you can repro, if you need anything else let me know.
@dmarkey fix provided in #2475
@dmarkey this has been released to PyPI as version 0.49.2, let us know if the issue persists!
Which version of dd-trace-py are you using?
ddtrace==0.48.4
Which version of pip are you using?
pip 20.0.1
ddtrace requires pip>=18 to install one of our pre-built wheels
Which version of the libraries are you using?
How can we reproduce your problem?
When using
patch_all()
and using Mongoengine, connection times were very erratic and sometime taking 15+ seconds. This consumed nearly all our UWSGI workers.What is the result that you get?
Endpoints became extremely slow.
What is the result that you expected?
Performance is not effected.
We were about to track down and isolate the problem with: