Fwd: [webpy] Nginx + WSGI == Blazing Fast!

4 views
Skip to first unread message

Zoom.Quiet

unread,
Jan 7, 2008, 7:50:28 PM1/7/08
to Python.cn@google, python-chinese列表, cpug-ea...@googlegroups.com, zp...@googlegroups.com
Here is the configuration files and the code used for both tests.

--------------------------------------------
Configuration file for Lighttpd
--------------------------------------------
server.modules = (
"mod_rewrite",
"mod_fastcgi",
)
server.document-root = "/var/www/"
server.errorlog = "/var/log/lighttpd/error.log"
server.pid-file = "/var/run/lighttpd.pid"

## virtual directory listings
dir-listing.encoding = "utf-8"
server.dir-listing = "enable"
server.username = "www-data"
server.groupname = "www-data"

fastcgi.server = ( "/code-fastcgi.py" =>
(( "socket" => "/tmp/fastcgi.socket",
"bin-path" => "/var/www/code-fastcgi.py",
"max-procs" => 1
))
)

url.rewrite-once = (
"^/favicon.ico$" => "/static/favicon.ico",
"^/static/(.*)$" => "/static/$1",
"^/(.*)$" => "/code-fastcgi.py/$1",
)

--------------------------------------------
Configuration file for Nginx
--------------------------------------------
worker_processes 2;
error_log logs/error.log info;
pid logs/nginx.pid;

events {
worker_connections 1024;
}


env HOME;
env PYTHONPATH=/usr/bin/python;

http {
include conf/mime.types;
default_type application/octet-stream;

sendfile on;
keepalive_timeout 65;

wsgi_python_optimize 2;
wsgi_python_executable /usr/bin/python;
wsgi_python_home /usr/;
wsgi_enable_subinterpreters on;

server {
listen 80;
server_name localhost;


include conf/wsgi_vars;

location / {
#client_body_buffer_size 50;
wsgi_pass /usr/local/nginx/nginx.py;

wsgi_pass_authorization off;
wsgi_script_reloading on;
wsgi_use_main_interpreter on;
}

location /wsgi {
#client_body_buffer_size 50;
wsgi_var TEST test;
wsgi_var FOO bar;
wsgi_var EMPTY "";
# override existing HTTP_ variables
wsgi_var HTTP_USER_AGENT "nginx";
wsgi_var HTTP_COOKIE $http_cookie;

wsgi_pass /usr/local/nginx/nginx-2.py main;

wsgi_pass_authorization on;
wsgi_script_reloading off;
wsgi_use_main_interpreter off;
}

location /wsgi-webpy {
wsgi_pass /usr/local/nginx/webpy-code.py;
}
}
}

--------------------------------------------
Code for Lighttpd
--------------------------------------------
#!/usr/bin/env python

import web

urls = (
'/(.*)', 'hello'
)

class hello:
def GET(self, name):
i = web.input(times=1)
if not name: name = 'world'
for c in xrange(int(i.times)):
print 'Hello,', name+'!'

if __name__ == "__main__": web.run(urls, globals())

--------------------------------------------
Code for Nginx
--------------------------------------------
import web

urls = (
'/(.*)', 'hello'
)

class hello:
def GET(self, name):
i = web.input(times=1)
if not name: name = 'world'
for c in xrange(int(i.times)): print 'Hello,', name+'!'

application = web.wsgifunc(web.webpyfunc(urls, globals()))


---------- Forwarded message ----------
From: David Cancel <dca...@gmail.com>
Date: Jan 7, 2008 11:55 PM
Subject: [webpy] Nginx + WSGI == Blazing Fast!
To: "web.py" <we...@googlegroups.com>

I know.. I know... Simple benchmarks mean nothing but I couldn't help
playing with the new(ish) mod_wsgi module for my favorite webserver
Nginx.

Nginx: http://nginx.net/
Nginx mod_wsgi module: http://wiki.codemongers.com/NginxNgxWSGIModule

I tested Nginx vs. the recommended setup of Lighttpd/Fastcgi. These
very simple and flawed tests were run on Debian Etch running under
virtualization (Parallels) on my Macbook Pro. Hey I said they were
flawed.. :-)

The results show Nginx/WSGI performing 3x as fast as Lighttpd/Fastcgi,
over 1000 requests per second!!

I tested both with Keep-Alives on and off. I'm not sure why Nginx/WSGI
performed 2x as fast with keep-alives on.

*********** Full results below *************

--------------------------------------------
Nginx 0.5.34 - Keepalives On
---------------------------------------------
ab -c 10 -n 1000 -k http://10.211.55.4/wsgi-webpy/david
This is ApacheBench, Version 1.3d <$Revision: 1.73 $> apache-1.3

Server Software: nginx/
0.5.34
Server Hostname: 10.211.55.4
Server Port: 80

Document Path: /wsgi-webpy/david
Document Length: 14 bytes

Concurrency Level: 10
Time taken for tests: 0.970 seconds
Complete requests: 1000
Failed requests: 0
Broken pipe errors: 0
Keep-Alive requests: 1001
Total transferred: 136136 bytes
HTML transferred: 14014 bytes
** Requests per second: 1030.93 [#/sec] (mean) **
Time per request: 9.70 [ms] (mean)
Time per request: 0.97 [ms] (mean, across all concurrent
requests)
Transfer rate: 140.35 [Kbytes/sec] received

Connnection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.4 0 5
Processing: 1 9 4.3 9 26
Waiting: 0 9 4.2 9 25
Total: 1 9 4.3 9 26

Percentage of the requests served within a certain time (ms)
50% 9
66% 11
75% 12
80% 13
90% 15
95% 17
98% 20
99% 22
100% 26 (last request)

--------------------------------------------
Nginx 0.5.34 - No Keepalives
---------------------------------------------
ab -c 10 -n 1000 http://10.211.55.4/wsgi-webpy/david
This is ApacheBench, Version 1.3d <$Revision: 1.73 $> apache-1.3

Server Software: nginx/
0.5.34
Server Hostname: 10.211.55.4
Server Port: 80

Document Path: /wsgi-webpy/david
Document Length: 14 bytes

Concurrency Level: 10
Time taken for tests: 2.378 seconds
Complete requests: 1000
Failed requests: 0
Broken pipe errors: 0
Total transferred: 131131 bytes
HTML transferred: 14014 bytes
** Requests per second: 420.52 [#/sec] (mean) **
Time per request: 23.78 [ms] (mean)
Time per request: 2.38 [ms] (mean, across all concurrent
requests)
Transfer rate: 55.14 [Kbytes/sec] received

Connnection Times (ms)
min mean[+/-sd] median max
Connect: 0 4 2.9 3 26
Processing: 8 19 8.8 18 136
Waiting: 0 19 8.8 17 135
Total: 8 23 8.9 21 142

Percentage of the requests served within a certain time (ms)
50% 21
66% 24
75% 26
80% 28
90% 34
95% 40
98% 45
99% 47
100% 142 (last request)

*********************************************************************

--------------------------------------------
Lighttpd 1.4.13 - Keepalives On
---------------------------------------------
ab -c 10 -n 1000 -k http://10.211.55.4/david
This is ApacheBench, Version 1.3d <$Revision: 1.73 $> apache-1.3

Server Software: lighttpd/
1.4.13
Server Hostname: 10.211.55.4
Server Port: 80

Document Path: /david
Document Length: 14 bytes

Concurrency Level: 10
Time taken for tests: 2.901 seconds
Complete requests: 1000
Failed requests: 1
(Connect: 0, Length: 1, Exceptions: 0)
Broken pipe errors: 0
Keep-Alive requests: 942
Total transferred: 138711 bytes
HTML transferred: 14001 bytes
** Requests per second: 344.71 [#/sec] (mean) **
Time per request: 29.01 [ms] (mean)
Time per request: 2.90 [ms] (mean, across all concurrent
requests)
Transfer rate: 47.81 [Kbytes/sec] received

Connnection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 1.1 0 21
Processing: 3 28 29.3 22 385
Waiting: 3 28 29.3 22 385
Total: 3 28 29.3 22 385

Percentage of the requests served within a certain time (ms)
50% 22
66% 26
75% 31
80% 34
90% 48
95% 60
98% 100
99% 164
100% 385 (last request)

--------------------------------------------
Lighttpd 1.4.13 - No Keepalives
---------------------------------------------
ab -c 10 -n 1000 http://10.211.55.4/david
This is ApacheBench, Version 1.3d <$Revision: 1.73 $> apache-1.3

Server Software: lighttpd/
1.4.13
Server Hostname: 10.211.55.4
Server Port: 80

Document Path: /david
Document Length: 14 bytes

Concurrency Level: 10
Time taken for tests: 4.017 seconds
Complete requests: 1000
Failed requests: 1
(Connect: 0, Length: 1, Exceptions: 0)
Broken pipe errors: 0
Total transferred: 134269 bytes
HTML transferred: 14029 bytes
** Requests per second: 248.94 [#/sec] (mean) **
Time per request: 40.17 [ms] (mean)
Time per request: 4.02 [ms] (mean, across all concurrent
requests)
Transfer rate: 33.43 [Kbytes/sec] received

Connnection Times (ms)
min mean[+/-sd] median max
Connect: 0 3 4.9 2 68
Processing: 3 36 49.6 28 852
Waiting: 2 35 49.6 28 852
Total: 3 39 50.1 30 855

Percentage of the requests served within a certain time (ms)
50% 30
66% 36
75% 41
80% 44
90% 61
95% 87
98% 148
99% 252
100% 855 (last request)


--
'''Time is unimportant, only life important!
过程改进乃是开始催生可促生靠谱的人的组织!
'''http://zoomquiet.org
博 @ http://blog.zoomquiet.org/pyblosxom/
维 @ http://wiki.woodpecker.org.cn/moin/ZoomQuiet
豆 @ http://www.douban.com/people/zoomq/
看 @ http://zoomq.haokanbu.com/
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Pls. usage OOo to replace M$ Office. http://zh.openoffice.org
Pls. usage 7-zip to replace WinRAR/WinZip. http://7-zip.org
You can get the truely Freedom 4 software.

luo roger

unread,
Jan 7, 2008, 8:36:17 PM1/7/08
to pyth...@googlegroups.com
好东西啊,仔细看看。这样新项目中能否就不用flup再转一道了,直接nginx+python app?

2008/1/8, Zoom. Quiet <zoom....@gmail.com>:

Jiahua Huang

unread,
Jan 7, 2008, 8:59:18 PM1/7/08
to pyth...@googlegroups.com
nginx 比 lighttpd 快那么多啊,

webpy + nginx 真是狂快……
居然跟 lighttpd 静态文件同一个数量级了

leopay

unread,
Jan 7, 2008, 9:16:53 PM1/7/08
to pyth...@googlegroups.com
On 1/8/08, Jiahua Huang <jhuang...@gmail.com> wrote:
nginx 比 lighttpd 快那么多啊,

webpy + nginx 真是狂快……
居然跟 lighttpd 静态文件同一个数量级了
 
nginx的WSGI Modules是Third-party的,一直还没有试过,没想到这么快啊

haur

unread,
Jan 7, 2008, 9:40:16 PM1/7/08
to pyth...@googlegroups.com
不支持WINDOWS不好调试啊,平时。。。。。

Bruce Wang

unread,
Jan 7, 2008, 9:48:50 PM1/7/08
to pyth...@googlegroups.com
On Jan 8, 2008 10:16 AM, leopay <leo...@gmail.com> wrote:
On 1/8/08, Jiahua Huang <jhuang...@gmail.com> wrote:
nginx 比 lighttpd 快那么多啊,

webpy + nginx 真是狂快……
居然跟 lighttpd 静态文件同一个数量级了
 
nginx的WSGI Modules是Third-party的,一直还没有试过,没想到这么快啊
 


nginx 很cool, 我已经决定将我所有项目迁移到nginx上了。

有没有内存使用的统计数据呢? 总觉得mod_python和mod_wsgi 这种工作模式内存消耗很不靠谱

PS: nginx 直接加python app很简单啊,nginx proxy + paste http or cherrypy 就ok啦 (我更倾向于这种配置)


--
simple is good
http://brucewang.net
http://io.brucewang.net
http://twitter.com/number5
skype: number5

Jiahua Huang

unread,
Jan 7, 2008, 9:53:15 PM1/7/08
to pyth...@googlegroups.com
On Jan 8, 2008 10:48 AM, Bruce Wang <num...@gmail.com> wrote:
>
> nginx 很cool, 我已经决定将我所有项目迁移到nginx上了。
>
> 有没有内存使用的统计数据呢? 总觉得 mod_python 和 mod_wsgi 这种工作模式内存消耗很不靠谱
>

对 apache mod_python 的速度和开销不强烈不满,
比 lighttpd fcgi 差太多了

>
> PS: nginx 直接加python app很简单啊,nginx proxy + paste http or cherrypy 就ok啦
> (我更倾向于这种配置)

就是觉得 web.py 自带 cherrypy 不够快才要 fcgi/scgi/wsgi 的嘛

Jiahua Huang

unread,
Jan 7, 2008, 9:54:38 PM1/7/08
to pyth...@googlegroups.com
平时跑个 Ubuntu 也没问题呀,
有同事是 XP 下 scrt 连 linux 做东西

On Jan 8, 2008 10:40 AM, haur <hek...@gmail.com> wrote:
> 不支持WINDOWS不好调试啊,平时。。。。。
>
>

Bruce Wang

unread,
Jan 7, 2008, 10:09:18 PM1/7/08
to pyth...@googlegroups.com
nginx 0.5.34 的changlog里说支持cygwin了,你可以试试

顺便推荐一个 LEMP(Linux + EnginX(nginx) + MySQL + PHP) 的连接 XD
http://www.howtoforge.com/lemp_nginx_mysql_php_ubuntu_debian
 

Yingbo Qiu

unread,
Jan 7, 2008, 10:48:06 PM1/7/08
to pyth...@googlegroups.com
大概很长一段时间里,偶还是得坚定不移的走 apache 2.2 路线

On Jan 8, 2008 10:48 AM, Bruce Wang <num...@gmail.com> wrote:
>
>
>

Bruce Wang

unread,
Jan 7, 2008, 11:03:07 PM1/7/08
to pyth...@googlegroups.com
On Jan 8, 2008 11:48 AM, Yingbo Qiu <qiuy...@gmail.com> wrote:
大概很长一段时间里,偶还是得坚定不移的走 apache 2.2 路线


引诱一下
Nginx 有很棒的POP3/IMAP proxy功能,据说Zimbra在用哦 (邪恶的笑)

[1] http://www.highscalability.com/nginx-high-performance-smpt-pop-imap-proxy
[2] http://www.zimbra.com/

大郎

unread,
Jan 7, 2008, 11:12:31 PM1/7/08
to pyth...@googlegroups.com
当我收藏 Nginx时, 发现原来 ROR, pylons, tg都有不同程度的使用者. :)
--
http://del.icio.us/iexper
http://twitter.com/qichangxing
http://webpy.org
http://blog.hi0791.com (build with web.py)
Gtalk: iexper(at)gmail.com

haur

unread,
Jan 7, 2008, 11:18:51 PM1/7/08
to pyth...@googlegroups.com
turbogears 怎么配nginx 我的ubuntu下nginx可以跑咯。。。。

Jiahua Huang

unread,
Jan 7, 2008, 11:48:50 PM1/7/08
to pyth...@googlegroups.com
为啥 www.zimbra.com 的标示是
Server: Apache/2.0.46 (Red Hat)


On Jan 8, 2008 12:03 PM, Bruce Wang <num...@gmail.com> wrote:

Yingbo Qiu

unread,
Jan 8, 2008, 12:01:02 AM1/8/08
to pyth...@googlegroups.com
> > 大概很长一段时间里,偶还是得坚定不移的走 apache 2.2 路线
> 引诱一下
> Nginx 有很棒的POP3/IMAP proxy功能,据说Zimbra在用哦 (邪恶的笑)
>
> [1]
> http://www.highscalability.com/nginx-high-performance-smpt-pop-imap-proxy
> [2] http://www.zimbra.com/

又仔细看了一下这个 benchmark,原来 py 和 nginx 是在同一台服务器上
等我们能把应用和存储分离了再说吧,呵呵
传统的 SQL 应用倒是适合这样的模式.

luo roger

unread,
Jan 8, 2008, 12:22:06 AM1/8/08
to pyth...@googlegroups.com
说的是zimbra的邮件。
nginx的POP/IMAP的proxy功能,初一看的时候,真的匪夷所思。真的是只听说过,没有用过,也不知道谁在用。

在08-1-8,Yingbo Qiu <qiuy...@gmail.com > 写道:
Reply all
Reply to author
Forward
0 new messages