Evg
Evg

Reputation: 3080

memory leak - gunicorn + django + mysqldb

I have memory leak in my gunicorn + django 1.5.1 + mysqldb. I start to explore my code with gc and objgraph

when gunicorn worker became over 300mb i collected some stats:

data['sum_leak'] = sum((getsizeof(o) for o in objgraph.get_leaking_objects()))  #2 mb
data['total_objects_length'] = sum((getsizeof(o) for o in gc.get_objects()))    #6 mb 

so where only 2+6=8 mb, while gunicorn worker over 300 mb.

So i think problem not in python code, it's deeper.

I have: gunicorn==0.17.2 mysqldb==1.2.4

I update whem to 19.0.0 and 1.2.5 via pip install but pip frreze shows old versions while gunicorn -v and mysqldb.version_info show last updated.

So i think how to totaly reinstall gunicorn and mysqldb to be shure its totaly remove old ones (may be some old rudiments make problem) ?

Also i get with pmap some info:

pmap -x 805
805:   /usr/bin/python /usr/local/bin/gunicorn engine.wsgi:application -b 127.0.0.1:9005 --workers=2
Address   Kbytes     RSS   Dirty Mode   Mapping
08048000       0    1444       0 r-x--  python2.7
0829e000       0       4       4 r----  python2.7
0829f000       0     204     120 rw---  python2.7
082f4000       0      44      44 rw---    [ anon ]
09947000       0    3360    3360 rw---    [ anon ]
09c91000       0  253204  253204 rw---    [ anon ]
b5500000       0       4       4 rw---    [ anon ]
b5521000       0       0       0 -----    [ anon ]
b56d5000       0       0       0 -----    [ anon ]
b56d6000       0    1552    1552 rw---    [ anon ]
b6257000       0      12       0 r-x--  libpcre.so.3.12.1

it seem leak here - 09c91000 0 253204 253204 rw--- [ anon ]

but i don't know what to do with this.

Need help with some ways how to fix this leak?

Upvotes: 6

Views: 8660

Answers (1)

Ionut Hulub
Ionut Hulub

Reputation: 6326

If you think the problem if caused by gunicorn workers there is a easy way to test the hypothesis:

Start the workers with the parameter --max-requests *some positive number*

This will make gunicorn restart every worker after it has served the specified number of requests.

In the documentation they say: This is a simple method to help limit the damage of memory leaks.

Upvotes: 15

Related Questions