【问题标题】:django and guppy to find which import needs more memorydjango 和 guppy 查找哪个导入需要更多内存
【发布时间】:2012-05-21 03:45:23
【问题描述】:

我关注了tutorial 以安装 guppy 并配置我的 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.>

【问题讨论】:

    标签: django profiling


    【解决方案1】:

    FWIW。 Python web 应用程序在 Apache/mod_wsgi 下会比在不同的 WSGI 服务器(如 uWSGI 或 gunicorn)下消耗更多内存,没有具体原因。在可比较的配置下,Web 应用程序的每个进程的内存需求应该大致相同,因为您的应用程序不会以任何不同的方式运行。唯一可能会有所不同的是服务器配置是否是多线程的,并且您正在与单线程配置进行比较。

    还要注意您正在查看的内存量度。使用 RSS 而不是虚拟内存大小。见:

    http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Memory_Constrained_VPS_Systems

    【讨论】:

      猜你喜欢
      • 2013-08-10
      • 1970-01-01
      • 1970-01-01
      • 2014-09-01
      • 2019-08-14
      • 2019-11-20
      • 2020-10-11
      • 2019-12-06
      相关资源
      最近更新 更多