Created
August 14, 2012 09:08
-
-
Save rozza/3347715 to your computer and use it in GitHub Desktop.
Leak Hunting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mongoengine import * | |
import objgraph | |
import random | |
import inspect | |
def main(): | |
""" | |
Run by calling: python leak.py | |
Test memory usage by calling: | |
watch -n 1 " ps u -C 'python leak.py' | awk '"'{sum=sum+$6}; END {print sum/1024}'"' " | |
""" | |
class ListDoc(EmbeddedDocument): | |
some_var = StringField(default='test') | |
class TestDoc(Document): | |
a_list = ListField(EmbeddedDocumentField(ListDoc)) | |
TestDoc.drop_collection() | |
TestDoc(a_list=[ListDoc()]).save() | |
def loop1(): | |
i = 0 | |
while i < 100000: | |
t = TestDoc.objects.first() | |
del(t) | |
i += 1 | |
def loop2(): | |
i = 0 | |
while i < 100000: | |
t = TestDoc.objects.first() | |
t.a_list[0] # <= Here goes leaks | |
del(t) | |
i += 1 | |
objgraph.show_growth(limit=10) | |
loop2() | |
objgraph.show_growth() | |
if __name__ == "__main__": | |
conn = connect(db='mongoenginetest') | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment