用cython编译的版本替换选定的django模块,以提高速度。
django_speedboost的Python项目详细描述
Django SpeedBoost
用cython编译的版本替换选定的django模块,以提高速度。
基本原理
代码总是有瓶颈,django也不例外。通过用cython有选择地编辑django的热点, 我们可以让它走得更快。django speedboost是一个插件模块,在安装时用它的 基于cython的版本。
要求
- Python:2.7
- django:1.8.8
django speedboost的测试套件在安装后运行django测试套件,以验证它不会执行任何操作 不相容的。
安装
Django SpeedBoost目前仅为Django 1.8.8编译。安装时使用:
pip install django_speedboost
如果缺少头编译错误,请安装发行版的python库开发头,用于 ubuntu上的示例:
sudo apt-get install libpython-dev
工作原理
django speedboost包含一个.pth文件,允许它在python解释器加载点导入自己。 它使用这个来安装一个导入钩子,该钩子检测django子模块的加载以替换它们。
当前更换的模块:
- django.template.context
- django.template.context_processors
- django.template.base
- django.template.defaulttags
结果
在apache 2后面使用wsgi设置django,ab在加载的管理页面上显示了一致的13%的加载时间减少 内联和字段的数目:
(venv)ddalex@watson ~/Projects/backend(T7569)$ diff --side-by-side without_so.txt with_so.txt This is ApacheBench, Version 2.3 <$Revision: 1604373 $> This is ApacheBench, Version 2.3 <$Revision: 1604373 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.ze Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.ze Licensed to The Apache Software Foundation, http://www.apache Licensed to The Apache Software Foundation, http://www.apache Benchmarking guest (be patient).....done Benchmarking guest (be patient).....done Server Software: Apache/2.4.7 Server Software: Apache/2.4.7 Server Hostname: guest Server Hostname: guest Server Port: 80 Server Port: 80 Document Path: /admin/model/object/57/ Document Path: /admin/model/object/57/ Document Length: 619067 bytes Document Length: 619067 bytes Concurrency Level: 2 Concurrency Level: 2 Time taken for tests: 15.724 seconds | Time taken for tests: 13.932 seconds Complete requests: 20 Complete requests: 20 Failed requests: 0 Failed requests: 0 Total transferred: 12390600 bytes Total transferred: 12390600 bytes HTML transferred: 12381340 bytes HTML transferred: 12381340 bytes Requests per second: 1.27 [#/sec] (mean) | Requests per second: 1.44 [#/sec] (mean) Time per request: 1572.402 [ms](mean)| Time per request: 1393.243 [ms](mean) Time per request: 786.201 [ms](mean, across all concur | Time per request: 696.621 [ms](mean, across all concur Transfer rate: 769.54 [Kbytes/sec] received | Transfer rate: 868.49 [Kbytes/sec] received Connection Times (ms) Connection Times (ms) min mean[+/-sd] median max min mean[+/-sd] median max Connect: 000.1 01| Connect: 000.0 00 Processing: 6241570723.5 20082313| Processing: 5851391578.5 17641991 Waiting: 6211566722.6 19992311| Waiting: 5721381578.2 17411988 Total: 6241570723.5 20082313| Total: 5851391578.5 17641991 Percentage of the requests served within a certain time(ms) Percentage of the requests served within a certain time(ms)50% 2008|50% 176466% 2106|66% 184575% 2237|75% 191780% 2263|80% 193690% 2288|90% 198195% 2313|95% 199198% 2313|98% 199199% 2313|99% 1991100% 2313(longest request)|100% 1991(longest request)
历史记录
未来
1.8.8.0(2016-01-06)
- 第一个正确的django 1.8.8版本。替换django.template中的4个模块。