Django严重的内存泄漏

时间:2016-03-23 13:57:24

标签: django memory-leaks server

我面临服务器上存在大量内存泄漏的问题,使用Apache或Ngnix服务于Django(1.8)应用程序(两者都有问题)。

当我进入某些页面时(让我们说下面的具体请求),服务器的RAM在几秒钟内上升到16 G(只有一个请求)并且服务器冻结。

def records(request):
    """Return list 14 last records page. """
    values = []
    time = timezone.now() - timedelta(days=14)
    record =Records.objetcs.filter(time__gte=time)
    return render(request,
                  'record_app/records_newests.html',
                  {
                      'active_nav_tab': ["active", "", "", ""]
                      ' record': record, 
                  })

当我把结帐到旧版本时,回到没有这样的问题时,问题仍然存在,我也有同样的问题。

我在Gumpy进行了内存检查,结果是错误的请求:

>>> hp.heap()
Partition of a set of 7042 objects. Total size = 8588675016 bytes.
 Index  Count   %     Size   % Cumulative  % Kind (class / dict of class)
     0   1107  16 8587374512 100 8587374512 100 unicode
     1   1014  14   258256   0 8587632768 100 django.utils.safestring.SafeText
     2     45   1   150840   0 8587783608 100 dict of 0x390f0c0
     3    281   4    78680   0 8587862288 100 dict of django.db.models.base.ModelState
     4    326   5    75824   0 8587938112 100 list
     5     47   1    49256   0 8587987368 100 dict of 0x38caad0
     6     47   1    49256   0 8588036624 100 dict of 0x39ae590
     7     46   1    48208   0 8588084832 100 dict of 0x3858ab0
     8     46   1    48208   0 8588133040 100 dict of 0x38b8450
     9     46   1    48208   0 8588181248 100 dict of 0x3973fe0
<164 more rows. Type e.g. '_.more' to view.>

1 个答案:

答案 0 :(得分:0)

经过一天的搜索,我找到了答案。

在调查时,我检查了我的数据库的统计数据,发现有些表是800Mo大但只有900行。此表包含没有max len的Textfield。不知何故,一个文本字段插入了大量数据,这一行使用此模型减慢了每个页面上的所有内容。

相关问题