Pprint模块在32位系统中与Django一起工作缓慢

时间:2011-12-28 22:33:39

标签: 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)

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

以下是分析脚本:

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位中快?如果我可以设置一些东西以使其快速。

1 个答案:

答案 0 :(得分:5)

  

为什么pprint._safe_repr在Python 2.7 32位中如此慢,在64位中快?

64位不快。你的同事得到的更少ncalls

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