我试图调试为什么python manage.py runserver
需要差不多两分钟才能运行。我一直在挖掘并找到了cProfile。
python -m cProfile -o file.prof manage.py runserver
给了我:
Wed Mar 2 12:35:24 2016 file.prof
5705092 function calls (3261657 primitive calls) in 1491.228 seconds
Ordered by: internal time
List reduced from 11227 to 5 due to restriction <5>
ncalls tottime percall cumtime percall filename:lineno(function)
6 1392.536 232.089 1392.536 232.089 {built-in method waitpid}
2860672/492602 45.990 0.000 51.664 0.000 /usr/lib/python3.4/json/encoder.py:325(_iterencode_dict)
492602 7.650 0.000 59.315 0.000 /usr/lib/python3.4/json/encoder.py:404(_iterencode)
517899/517898 4.323 0.000 4.766 0.000 {built-in method isinstance}
32 3.766 0.118 63.099 1.972 /usr/lib/python3.4/json/encoder.py:175(encode)
这里的格式很难,但waitpid
占用了大部分时间(尽管我怀疑它可能是运行探查器的结果)。 /usr/lib/python3.4/json/encoder.py:325(_iterencode_dict)
也差不多46秒。我怎样才能深入挖掘这个?我应该在哪里转?这个输出有什么明显的吗?