Too many open file descriptors while using memcache
|Reported by:||m.gajda@…||Owned by:||haxoza|
|Component:||Core (Cache system)||Version:||1.4|
|Severity:||Normal||Keywords:||cache memcache open file descriptors|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||yes|
I am using Django 1.3.1 with memcached server under Linux (PLD distro). Django application is run with runfcgi command (maxspare set to 20). After switching to Django 1.3.1 (from line 1.2.x) I encountered very strange behaviour -- the app became crashing after some time.
What I have discovered is very large number of open socket connections made by the Django app to the memcached server (lsof show hundrets of open descriptors). After some time the app process had been killed by the system, due to exceeded number of opened file descriptors.
Look at Google pointed me to the ticket #15324. Since that patch has been incorporated in the Django 1.3.1, I have started digging into memcached Django wrapper over the pyton-memcached module (django.core.cache.backends.memcached). What I found is that Django app run in multithreaded mode creates new cache object for every thread. This is probably good information, since it has allowed avoid difficult race conditions. What is sad - after closing/releasing the thread, the cache object is somehow not deleted properly. I mean it seems that it does not clean up all gathered resources properly. This lasts with large number of opened file descriptors in the memcached case.
I have added simple patch fixing said behaviour. It works quite well for me, thus I assume I could be considered to be improved and somehow merged with the Django sources. I have not created any tests, I am sorry for that.
Change History (9)
Changed 4 years ago by m.gajda@…
comment:1 Changed 4 years ago by jezdez
- Needs documentation set
- Needs tests set
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted
- Version changed from 1.3 to 1.4
comment:3 Changed 3 years ago by haxoza
- Owner changed from nobody to haxoza
- Status changed from new to assigned