django-elasticsearch-debug-toolbar icon indicating copy to clipboard operation
django-elasticsearch-debug-toolbar copied to clipboard

Elasticsearch debug toolbar causes memory leak

Open igo opened this issue 8 years ago • 5 comments

Using Elasticsearch debug toolbar causes memory leak and thus crash when elasticsearch is extensively used. Not sure if this is general debug-toolbar problem or specific for elasticsearch-debug-toolbar but I did not notice this problem with other panels. Seems like after each elastic query an elastic_panel.panel.ElasticQueryInfo instance is created which resides in memory forever. I used http://mg.pov.lt/objgraph/objgraph.html#objgraph.show_growth to find out what objects are kept in memory. During tests I ended up with more than 100.000 of ElasticQueryInfo instances.

igo avatar Dec 08 '16 12:12 igo

I am not surprised, Django itself as leaks in DEBUG mode because it is keeping some references. But in this case those objects should be cleared when collector.clear_collection() is called. And this is done for every request. This is probably a django debug toolbar issue.

Benoss avatar Jan 17 '17 00:01 Benoss

It leaks even with DEBUG=False. Question is why is this leak relevant only for django-elasticsearch-debug-toolbar and not for every debug-toolbar plugin?

igo avatar Jan 17 '17 10:01 igo

I'will try to investigate, but if you have any idea do not hesitate :)

Benoss avatar Jan 18 '17 01:01 Benoss

I think the patched_log_request_success keeps a history for every thread (DEBUG or not) (invoked by Connections), but suspect that the collector.clear_collection() only runs for the thread in charge of the panel (and only when DEBUG), leaving the other thread histories to leak.

ggaughan avatar Oct 04 '17 09:10 ggaughan

Good catch, The collector is part of core debug toolbar, This plugin should not be the only one leaking :(

Benoss avatar Oct 07 '17 22:10 Benoss