<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tim[后端技术] &#187; flup</title>
	<atom:link href="http://timyang.net/tag/flup/feed/" rel="self" type="application/rss+xml" />
	<link>http://timyang.net</link>
	<description>Tim&#039;s blog, 关于后端架构、互联网技术、分布式、大型网络应用、NoSQL、Key Value等</description>
	<lastBuildDate>Mon, 02 Aug 2010 15:34:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>python web.py使用flup lighttpd优化过程</title>
		<link>http://timyang.net/python/python-webpy-lighttpd/</link>
		<comments>http://timyang.net/python/python-webpy-lighttpd/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 06:45:46 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[flup]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[web.py]]></category>

		<guid isPermaLink="false">http://timyang.net/?p=40</guid>
		<description><![CDATA[前文用Python实现CRUD功能REST服务中发现，一个普通的web.py页面每秒只能执行数十次requests，经网友Arbow提醒, web.py默认是单线程方式，所以性能提升困难，并推荐了一些高性能的web framework。同时也看到Python资深网友ZoomQuiet的总结 Pythonic Web 应用平台对比，因此觉得有必要换一种更强的web framework。同时也研究了国内著名的豆瓣所采用的Quixote框架。但由于牵涉到更换之后web.py中的REST接口代码实现要调整，所以就暂时搁置了。
后来看到搜狐qiuyingbo在lighttpd 2.0一文中提到sohu mail也是用web.py, 在向qiuyingbo请教之后，了解到web.py通过fastcgi多进程方式也可以实现高性能的访问，决定不再换框架了。
qiuyingbo推荐使用nginx+flup+webpy, 但是最近nginx的mod_wsgi页面中的 http://wiki.codemongers.com/NginxNgxWSGIModule 下载链接始终不能访问，所以就转向 lighttpd/fastcgi 方式，国外著名的reddit也是采用此架构，性能上应该不会有很大的差异。
在安装了lighttpd和配置之后，目前调用一个helloworld.py在本地一普通服务器上可以每秒达到1000次左右，在一个更专业的4核服务器上，执行速度更可4,000次。基本上可以满足运营的要求。
另外赖勇浩在blog我常用的几个第三方 Python 库中提到，使用psyco可以提升Python 40%或更高的性能。在32bit Linux下，测试上面的场景可提高约10%的性能。但由于Psyco不支持64bit架构，所以正式的生产环境就没有安装这个加速功能。
具体配置过程如下，假定lighttpd安装在/data0/lighttpd下:

Install Lighttpd, Download lighttpd http://www.lighttpd.net/download/lighttpd-1.4.21.tar.gz

./configure &#8211;prefix=/data0/lighttpd &#8211;with-openssl; make; make install
cp docs/lighttpd.conf /data0/lighttpd/sbin
openssl req -new -x509 -keyout lighttpd.pem -out lighttpd.pem -days 365 -nodes

Install Python 2.6, 具有内置Json支持 http://www.python.org/ftp/python/2.6.1/Python-2.6.1.tgz

./configure; make; make install

Install web.py http://webpy.org/static/web.py-0.31.tar.gz

python setup.py install

Install flup, http://www.saddi.com/software/flup/dist/flup-1.0.1.tar.gz


Install lighttpd + [...]]]></description>
			<content:encoded><![CDATA[<p>前文<a href="../../python/python-rest/">用Python实现CRUD功能REST服务</a>中发现，一个普通的web.py页面每秒只能执行数十次requests，经网友Arbow提醒, web.py默认是单线程方式，所以性能提升困难，并推荐了一些高性能的web framework。同时也看到Python资深网友<a href="http://blog.zoomquiet.org/pyblosxom" target="_blank">ZoomQuiet</a>的总结 <a href="http://wiki.woodpecker.org.cn/moin/PyWebFrameVs" target="_blank">Pythonic Web 应用平台对比</a>，因此觉得有必要换一种更强的web framework。同时也研究了国内著名的豆瓣所采用的<a href="http://quixote.ca/" target="_blank">Quixote</a>框架。但由于牵涉到更换之后web.py中的REST接口代码实现要调整，所以就暂时搁置了。</p>
<p>后来看到搜狐qiuyingbo在<a href="http://www.dup2.org/node/988" target="_blank">lighttpd 2.0</a>一文中提到sohu mail也是用web.py, 在向qiuyingbo请教之后，了解到web.py通过fastcgi多进程方式也可以实现高性能的访问，决定不再换框架了。</p>
<p>qiuyingbo推荐使用nginx+flup+webpy, 但是最近nginx的mod_wsgi页面中的 http://wiki.codemongers.com/NginxNgxWSGIModule 下载链接始终不能访问，所以就转向 lighttpd/fastcgi 方式，国外著名的reddit也是采用此架构，性能上应该不会有很大的差异。</p>
<p>在安装了lighttpd和配置之后，目前调用一个helloworld.py在本地一普通服务器上可以每秒达到1000次左右，在一个更专业的4核服务器上，执行速度更可4,000次。基本上可以满足运营的要求。</p>
<p>另外赖勇浩在blog<a href="http://blog.csdn.net/lanphaday/archive/2008/09/23/2966811.aspx" target="_blank">我常用的几个第三方 Python 库</a>中提到，使用<a href="http://psyco.sourceforge.net/" target="_blank">psyco</a>可以提升Python 40%或更高的性能。在32bit Linux下，测试上面的场景可提高约10%的性能。但由于Psyco不支持64bit架构，所以正式的生产环境就没有安装这个加速功能。</p>
<p>具体配置过程如下，假定lighttpd安装在/data0/lighttpd下:</p>
<ul>
<li>Install Lighttpd, Download lighttpd http://www.lighttpd.net/download/lighttpd-1.4.21.tar.gz</li>
</ul>
<p>./configure &#8211;prefix=/data0/lighttpd &#8211;with-openssl; make; make install<br />
cp docs/lighttpd.conf /data0/lighttpd/sbin<br />
openssl req -new -x509 -keyout lighttpd.pem -out lighttpd.pem -days 365 -nodes</p>
<ul>
<li>Install Python 2.6, 具有内置Json支持 http://www.python.org/ftp/python/2.6.1/Python-2.6.1.tgz</li>
</ul>
<p>./configure; make; make install</p>
<ul>
<li>Install web.py http://webpy.org/static/web.py-0.31.tar.gz</li>
</ul>
<p>python setup.py install</p>
<ul>
<li>Install flup, http://www.saddi.com/software/flup/dist/flup-1.0.1.tar.gz</li>
</ul>
<ul>
<li>Install lighttpd + fastcgi with web.py</li>
</ul>
<p>fastcgi.server = ( &#8220;/main.py&#8221; =&gt;<br />
(<br />
( &#8220;socket&#8221; =&gt; &#8220;/tmp/fastcgi.socket&#8221;,<br />
&#8220;bin-path&#8221; =&gt; &#8220;/data0/lighttpd/www/python/main.py&#8221;,<br />
&#8220;max-procs&#8221; =&gt; 50,<br />
&#8220;bin-environment&#8221; =&gt; (<br />
&#8220;REAL_SCRIPT_NAME&#8221; =&gt; &#8220;&#8221;<br />
), &#8220;check-local&#8221; =&gt; &#8220;disable&#8221;<br />
)</p>
<p>)<br />
)</p>
<p>url.rewrite-once = (<br />
&#8220;^/favicon.ico$&#8221; =&gt; &#8220;/static/favicon.ico&#8221;,<br />
&#8220;^/static/(.*)$&#8221; =&gt; &#8220;/static/$1&#8243;,<br />
&#8220;^/(.*)$&#8221; =&gt; &#8220;/main.py/$1&#8243;,<br />
)</p>
<p>也可参看webpy官方的lighttpd fastcgi说明：<a href="http://webpy.org/cookbook/fastcgi-lighttpd" target="_blank">http://webpy.org/cookbook/fastcgi-lighttpd</a></p>
<ul>
<li>启动Lighttpd</li>
</ul>
<p>cd /data0/lighttpd/sbin; ./lighttpd -f lighttpd.conf</p>
Similar Posts:<ul><li><a href="http://timyang.net/programming/thrift-protocol-buffers-java-howto/" rel="bookmark" title="April 2, 2009">Thrift, Protocol Buffers installation and Java code howto</a></li>

<li><a href="http://timyang.net/web/nginx-module/" rel="bookmark" title="March 17, 2009">如何写nginx module</a></li>

<li><a href="http://timyang.net/linux/gearman-monitor/" rel="bookmark" title="August 26, 2009">利用Gearman来实现远程监控与管理</a></li>

<li><a href="http://timyang.net/python/python-rest/" rel="bookmark" title="February 12, 2009">用Python实现CRUD功能REST服务</a></li>

<li><a href="http://timyang.net/programming/c-erlang-java-performance/" rel="bookmark" title="November 11, 2009">C, Erlang, Java and Go Web Server performance test</a></li>
</ul><!-- Similar Posts took 22.212 ms -->]]></content:encoded>
			<wfw:commentRss>http://timyang.net/python/python-webpy-lighttpd/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
