我遵循这个tutorial来安装孔雀鱼并分析我的django应用程序。我的django应用程序没有内存泄漏,但由于某种奇怪的原因,它在Apache/mod_wsgi环境中需要大量内存。我被告知,我的一个导入可能是导致这个问题的原因。
如何使用guppy查看哪个导入占用更多内存?对于我的水平来说,guppy的输出信息不是很丰富。这就是它:
*** Connection 1 opened ***
<Monitor> lc
CID PID ARGV
1 2056 ['manage.py', 'runserver']
<Monitor> sc 1
Remote connection 1. To return to Monitor, type <Ctrl-C> or .<RETURN>
<Annex> int
Remote interactive console. To return to Annex, type '-'.
>>> hp.heap()
GC hook object was referred to from somebody!
Partition of a set of 128202 objects. Total size = 11015508 bytes.
Index Count % Size % Cumulative % Kind (class / dict of class)
0 55746 43 4117640 37 4117640 37 str
1 29278 23 1272920 12 5390560 49 tuple
2 2457 2 777324 7 6167884 56 dict (no owner)
3 495 0 583860 5 6751744 61 dict of module
4 8361 7 501660 5 7253404 66 function
5 7202 6 489736 4 7743140 70 types.CodeType
6 1026 1 461748 4 8204888 74 type
7 1022 1 402472 4 8607360 78 dict of type
8 179 0 250852 2 8858212 80 dict of django.db.models.fields.CharField
9 2599 2 156124 1 9014336 82 list
<486 more rows. Type e.g. '_.more' to view.>发布于 2012-05-14 08:03:06
FWIW。Python web应用程序在Apache/mod_wsgi下比在不同的WSGI服务器(如uWSGI或gunicorn )下消耗更多内存的原因并不明确。在可比较的配置下,web应用程序的每个进程的内存需求应该大致相同,因为您的应用程序不会有任何不同的运行。可能唯一有区别的是服务器配置是否是多线程的,并且您正在将其与单线程配置进行比较。
还要注意您正在查看的内存度量。使用RSS而不是虚拟内存大小。请参见:
http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Memory_Constrained_VPS_Systems
https://stackoverflow.com/questions/10570101
复制相似问题