python - Pprint 模块在 32 位系统中与 Django 配合使用缓慢

标签 python django performance profiling

我在装有 Python 2.7 的 32 位 Ubuntu 机器上使用 Django。我的开发服务器一直很慢,渲染任何页面大约需要 15 秒。我运行了 cProfile 测试以查看是什么工作如此缓慢。

好像是pprint模块。

这是我的统计数据:

ncalls       tottime percall cumtime percall filename:lineno(function)
272605/48718  24.238       0  49.213   0.001 pprint.py:247(_safe_repr)

这是我同事的,他运行 64 位 OS X:

14531/5334    1.016    0.000    2.199    0.000 pprint.py:247(_safe_repr)

同时我必须关闭 Debug模式才能正常使用开发服务器。

这是分析脚本:

from cProfile import Profile
from django.test.client import Client
import Cookie
cl = Client()
cl.cookies = Cookie.SimpleCookie({'sessionid':'7344ebeba093b65c1d59a9d7583f60bc'})
p = Profile()
p.runctx("c.get('/welcome/')", globals={'c': cl}, locals={})
p.print_stats()

(sessionid cookie 用于显示您需要登录的页面。)

我不确定32位系统是主要原因。

主要问题是:为什么 pprint._safe_repr 在 Python 2.7 32 位中这么慢而在 64 位中这么快?我是否可以设置一些东西让它变快。

最佳答案

Why is pprint._safe_repr so slow in Python 2.7 32 bits and fast in 64 bits?

它在 64 位上并不快。您的同事接到的 ncall 少得多。

您应该调查为什么单个 GET 会导致对 _safe_repr() 的如此大量的调用。

关于python - Pprint 模块在 32 位系统中与 Django 配合使用缓慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8662050/

相关文章:

Java:从 block 中的数组列表创建数组的有效方法

performance - Hive - 如何以最佳性能重用 Hive 中的子查询

python - 与 Timedelta 的时间差给出错误的结果

python - DataFrame - 值错误 : Unexpected tuple with StructType

python - 详细记录 Django 测试

c++ - 如何快速将元素重复插入到排序列表中

python - 为什么类 __dict__ 是映射代理?

python - 如何根据另一列中的值将 NaN 值替换为另一列的平均值? Pandas

python - Django - 使用通用 View 找不到 URL

django - 流式 HTTP 响应,刷新到浏览器