<?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>Yoichi Kawasaki&#039;s Web &#187; apache</title>
	<atom:link href="http://yk55.com/blog/tags/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://yk55.com/blog</link>
	<description>the place to organize and record my ideas ...</description>
	<lastBuildDate>Sun, 05 Feb 2012 15:16:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<!-- google_ad_section_end --><!-- google_ad_section_start(weight=ignore) -->	<item>
		<title>Segmentation fault(11) &#8211; Apache2 and libphp5.so on Ubuntu</title>
		<link>http://yk55.com/blog/2010/11/30/php5apache2_segmentation_fault_under_ubuntu/</link>
		<comments>http://yk55.com/blog/2010/11/30/php5apache2_segmentation_fault_under_ubuntu/#comments</comments>
		<pubDate>Mon, 29 Nov 2010 15:32:11 +0000</pubDate>
		<dc:creator>yoichi</dc:creator>
				<category><![CDATA[Environment Setup]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[gdb]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://yk55.com/blog/?p=434</guid>
		<description><![CDATA[Ubuntu10.04.1LTSでApache2、PHP5.3がうまく動いてくれない。 同一バージョンのApache、PHPを依存ライブラリをほぼ同じにしてdebian Lennyで試してみると問題なく動作する。 どうにもこうにもならないので後々のためにとりあえず記録だけ残しておく。 1. PROBLEM: Apache2 Segmentation fault(11) [Sun Nov 28 17:42:48 2010] [notice] Apache/2.2.2 (Unix) PHP/5.3.3 configured -- resuming normal operations [Sun Nov 28 17:42:48 2010] [notice] child pid 13032 exit signal Segmentation fault (11) [Sun Nov 28 17:42:49 2010] [notice] child pid 13033 exit signal Segmentation fault (11) [Sun Nov 28 17:42:52 [...]]]></description>
			<content:encoded><![CDATA[<p>Ubuntu10.04.1LTSでApache2、PHP5.3がうまく動いてくれない。 同一バージョンのApache、PHPを依存ライブラリをほぼ同じにしてdebian Lennyで試してみると問題なく動作する。 どうにもこうにもならないので後々のためにとりあえず記録だけ残しておく。 </p>
<p><h2><strong>1. PROBLEM: Apache2 Segmentation fault(11)</strong></h2>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[Sun Nov 28 17:42:48 2010] [notice] Apache/2.2.2 (Unix) PHP/5.3.3 configured -- resuming normal operations<br />
[Sun Nov 28 17:42:48 2010] [notice] child pid 13032 exit signal Segmentation fault (11)<br />
[Sun Nov 28 17:42:49 2010] [notice] child pid 13033 exit signal Segmentation fault (11)<br />
[Sun Nov 28 17:42:52 2010] [notice] child pid 13034 exit signal Segmentation fault (11)<br />
[Sun Nov 28 17:42:56 2010] [notice] child pid 13035 exit signal Segmentation fault (11)</div></div>
<p><h2><strong>2. Environments</strong></h2>
<p><h4><strong>Installations: apache-2.2.2</strong></h4>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">tar zxf httpd-2.2.2.tar.gz<br />
cd httpd-2.2.2<br />
<br />
CC=&quot;gcc&quot; OPTIM=&quot;-O2&quot; \<br />
&nbsp;./configure \<br />
&nbsp;--prefix=/home/apache-2.2.2 \<br />
&nbsp;--with-layout=Apache \<br />
&nbsp;--enable-rewrite \<br />
&nbsp;--disable-userdir \<br />
&nbsp;--enable-auth_dbm \<br />
&nbsp;--enable-usertrack \<br />
&nbsp;--enable-=so \<br />
&nbsp;--enable-proxy \<br />
&nbsp;--enable-proxy-http \<br />
&nbsp;--enable-proxy-connect \<br />
&nbsp;--enable-speling \<br />
&nbsp;--enable-headers \<br />
&nbsp;--enable-expires \<br />
&nbsp;--enable-setenvif \<br />
&nbsp;--enable-cache \<br />
&nbsp;--enable-disk-cache \<br />
&nbsp;--enable-mem-cache \<br />
&nbsp;--enable-info \<br />
&nbsp;--enable-rule=SHARED_CORE \<br />
&nbsp;--verbose<br />
<br />
make <br />
sudo make install<br />
sudo ln -s /home/apache-2.2.2 /home/apache</div></div>
<p><h4><strong>Installations: PHP-5.3.3</strong></h4>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">tar zxvf php-5.3.3.tar.gz<br />
cd php-5.3.3<br />
./configure \<br />
&nbsp; &nbsp; --with-apxs2=/home/apache/bin/apxs \<br />
&nbsp; &nbsp; --with-mysql=/home/mysql \<br />
&nbsp; &nbsp; --with-curl=/usr/lib \<br />
&nbsp; &nbsp; --with-zlib \<br />
&nbsp; &nbsp; --enable-mbstring \<br />
&nbsp; &nbsp; --enable-mbregex \<br />
<br />
make<br />
sudo make install</div></div>
<p><h4><strong>Linux distribution Info</strong></h4>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ lsb_release -a <br />
No LSB modules are available.<br />
Distributor ID: Ubuntu<br />
Description: &nbsp; &nbsp;Ubuntu 10.04.1 LTS<br />
Release: &nbsp; &nbsp; &nbsp; &nbsp;10.04<br />
Codename: &nbsp; &nbsp; &nbsp; lucid</div></div>
<p><h4><strong>Apache Info</strong></h4>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ /home/apache/bin/apachectl -V<br />
<br />
Server version: Apache/2.2.2<br />
Server built: &nbsp; Apr &nbsp;4 2010 10:26:51<br />
Server's Module Magic Number: 20051115:2<br />
Server loaded: &nbsp;APR 1.2.7, APR-Util 1.2.7<br />
Compiled using: APR 1.2.7, APR-Util 1.2.7<br />
Architecture: &nbsp; 32-bit<br />
Server MPM: &nbsp; &nbsp; Prefork<br />
&nbsp; threaded: &nbsp; &nbsp; no<br />
&nbsp; &nbsp; forked: &nbsp; &nbsp; yes (variable process count)<br />
Server compiled with....<br />
&nbsp;-D APACHE_MPM_DIR=&quot;server/mpm/prefork&quot; &nbsp; &nbsp; &lt;--- サーバは MPM/Prefork<br />
&nbsp;-D APR_HAS_SENDFILE<br />
&nbsp;-D APR_HAS_MMAP<br />
&nbsp;-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)<br />
&nbsp;-D APR_USE_SYSVSEM_SERIALIZE<br />
&nbsp;-D APR_USE_PTHREAD_SERIALIZE<br />
&nbsp;-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT<br />
&nbsp;-D APR_HAS_OTHER_CHILD<br />
&nbsp;-D AP_HAVE_RELIABLE_PIPED_LOGS<br />
&nbsp;-D DYNAMIC_MODULE_LIMIT=128<br />
&nbsp;-D HTTPD_ROOT=&quot;/home/apache-2.2.2&quot;<br />
&nbsp;-D SUEXEC_BIN=&quot;/home/apache-2.2.2/bin/suexec&quot;<br />
&nbsp;-D DEFAULT_PIDLOG=&quot;logs/httpd.pid&quot;<br />
&nbsp;-D DEFAULT_SCOREBOARD=&quot;logs/apache_runtime_status&quot;<br />
&nbsp;-D DEFAULT_LOCKFILE=&quot;logs/accept.lock&quot;<br />
&nbsp;-D DEFAULT_ERRORLOG=&quot;logs/error_log&quot;<br />
&nbsp;-D AP_TYPES_CONFIG_FILE=&quot;conf/mime.types&quot;<br />
&nbsp;-D SERVER_CONFIG_FILE=&quot;conf/httpd.conf&quot;</div></div>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ /home/apache/bin/apachectl -M<br />
<br />
Loaded Modules:<br />
&nbsp;core_module (static)<br />
&nbsp;authn_file_module (static)<br />
&nbsp;authn_default_module (static)<br />
&nbsp;authz_host_module (static)<br />
&nbsp;authz_groupfile_module (static)<br />
&nbsp;authz_user_module (static)<br />
&nbsp;authz_default_module (static)<br />
&nbsp;auth_basic_module (static)<br />
&nbsp;cache_module (static)<br />
&nbsp;disk_cache_module (static)<br />
&nbsp;mem_cache_module (static)<br />
&nbsp;include_module (static)<br />
&nbsp;filter_module (static)<br />
&nbsp;log_config_module (static)<br />
&nbsp;env_module (static)<br />
&nbsp;expires_module (static)<br />
&nbsp;headers_module (static)<br />
&nbsp;usertrack_module (static)<br />
&nbsp;setenvif_module (static)<br />
&nbsp;proxy_module (static)<br />
&nbsp;proxy_connect_module (static)<br />
&nbsp;proxy_ftp_module (static)<br />
&nbsp;proxy_http_module (static)<br />
&nbsp;proxy_ajp_module (static)<br />
&nbsp;proxy_balancer_module (static)<br />
&nbsp;mpm_prefork_module (static)<br />
&nbsp;http_module (static)<br />
&nbsp;mime_module (static)<br />
&nbsp;status_module (static)<br />
&nbsp;autoindex_module (static)<br />
&nbsp;asis_module (static)<br />
&nbsp;info_module (static)<br />
&nbsp;cgi_module (static)<br />
&nbsp;negotiation_module (static)<br />
&nbsp;dir_module (static)<br />
&nbsp;actions_module (static)<br />
&nbsp;speling_module (static)<br />
&nbsp;alias_module (static)<br />
&nbsp;rewrite_module (static)<br />
&nbsp;so_module (static)<br />
&nbsp;php5_module (shared)<br />
Syntax OK</div></div>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ ldd /home/apache/bin/httpd &nbsp; &nbsp;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; linux-gate.so.1 =&gt; &nbsp;(0x00ed3000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libm.so.6 =&gt; /lib/tls/i686/cmov/libm.so.6 (0x006c4000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libaprutil-1.so.0 =&gt; /home/apache-2.2.2/lib/libaprutil-1.so.0 (0x00586000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libexpat.so.1 =&gt; /lib/libexpat.so.1 (0x0087a000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libapr-1.so.0 =&gt; /home/apache-2.2.2/lib/libapr-1.so.0 (0x00f91000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; librt.so.1 =&gt; /lib/tls/i686/cmov/librt.so.1 (0x0093b000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libcrypt.so.1 =&gt; /lib/tls/i686/cmov/libcrypt.so.1 (0x005ce000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libpthread.so.0 =&gt; /lib/tls/i686/cmov/libpthread.so.0 (0x00115000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libdl.so.2 =&gt; /lib/tls/i686/cmov/libdl.so.2 (0x00964000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libc.so.6 =&gt; /lib/tls/i686/cmov/libc.so.6 (0x00413000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; /lib/ld-linux.so.2 (0x00d4f000)</div></div>
<p><h4><strong>PHP Info</strong></h4>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ php -i <br />
<br />
phpinfo()<br />
PHP Version =&gt; 5.3.3<br />
<br />
System =&gt; Linux ubuntu-xps 2.6.32-26-generic #47-Ubuntu SMP Wed Nov 17 15:59:05 UTC 2010 i686<br />
Build Date =&gt; Nov 28 2010 19:21:06<br />
Configure Command =&gt; &nbsp;'./configure' &nbsp;'--with-apxs2=/home/apache/bin/apxs' '--with-mysql=/home/mysql' '--with-curl=/usr/lib' '--with-zlib' '--enable-mbstring' '--enable-mbregex'<br />
Server API =&gt; Command Line Interface<br />
Virtual Directory Support =&gt; disabled<br />
Configuration File (php.ini) Path =&gt; /usr/local/lib<br />
Loaded Configuration File =&gt; (none)<br />
Scan this dir for additional .ini files =&gt; (none)<br />
Additional .ini files parsed =&gt; (none)<br />
PHP API =&gt; 20090626<br />
PHP Extension =&gt; 20090626<br />
Zend Extension =&gt; 220090626<br />
Zend Extension Build =&gt; API220090626,NTS<br />
PHP Extension Build =&gt; API20090626,NTS<br />
Debug Build =&gt; no<br />
Thread Safety =&gt; disabled<br />
Zend Memory Manager =&gt; enabled<br />
Zend Multibyte Support =&gt; disabled<br />
IPv6 Support =&gt; enabled<br />
Registered PHP Streams =&gt; compress.zlib, php, file, glob, data, http, ftp, phar &nbsp;<br />
Registered Stream Socket Transports =&gt; tcp, udp, unix, udg<br />
Registered Stream Filters =&gt; zlib.*, convert.iconv.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk<br />
<br />
<br />
This program makes use of the Zend Scripting Language Engine:<br />
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies</div></div>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ php -m<br />
<br />
[PHP Modules]<br />
Core<br />
ctype<br />
curl<br />
date<br />
dom<br />
ereg<br />
fileinfo<br />
filter<br />
hash<br />
iconv<br />
json<br />
libxml<br />
mbstring<br />
mysql<br />
pcre<br />
PDO<br />
pdo_sqlite<br />
Phar<br />
posix<br />
Reflection<br />
session<br />
SimpleXML<br />
SPL<br />
SQLite<br />
sqlite3<br />
standard<br />
tokenizer<br />
xml<br />
xmlreader<br />
xmlwriter<br />
zlib<br />
<br />
[Zend Modules]</div></div>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ ldd /home/apache/modules/libphp5.so <br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; linux-gate.so.1 =&gt; &nbsp;(0x00569000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libcrypt.so.1 =&gt; /lib/tls/i686/cmov/libcrypt.so.1 (0x00110000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; librt.so.1 =&gt; /lib/tls/i686/cmov/librt.so.1 (0x001f6000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libmysqlclient.so.16 =&gt; /home/mysql-5.1.30/lib/mysql/libmysqlclient.so.16 (0x00356000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libz.so.1 =&gt; /lib/libz.so.1 (0x00142000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libm.so.6 =&gt; /lib/tls/i686/cmov/libm.so.6 (0x00157000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libdl.so.2 =&gt; /lib/tls/i686/cmov/libdl.so.2 (0x0017d000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libnsl.so.1 =&gt; /lib/tls/i686/cmov/libnsl.so.1 (0x00181000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libcurl.so.4 =&gt; /usr/lib/libcurl.so.4 (0x00198000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libxml2.so.2 =&gt; /usr/lib/libxml2.so.2 (0x001ff000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libc.so.6 =&gt; /lib/tls/i686/cmov/libc.so.6 (0x00e02000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libpthread.so.0 =&gt; /lib/tls/i686/cmov/libpthread.so.0 (0x001dd000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; /lib/ld-linux.so.2 (0x00339000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libidn.so.11 =&gt; /usr/lib/libidn.so.11 (0x004ad000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; liblber-2.4.so.2 =&gt; /usr/lib/liblber-2.4.so.2 (0x0032a000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libldap_r-2.4.so.2 =&gt; /usr/lib/libldap_r-2.4.so.2 (0x004df000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libgssapi_krb5.so.2 =&gt; /usr/lib/libgssapi_krb5.so.2 (0x00526000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libssl.so.0.9.8 =&gt; /lib/i686/cmov/libssl.so.0.9.8 (0x00f5c000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libcrypto.so.0.9.8 =&gt; /lib/i686/cmov/libcrypto.so.0.9.8 (0x00fa4000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libresolv.so.2 =&gt; /lib/tls/i686/cmov/libresolv.so.2 (0x00555000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libsasl2.so.2 =&gt; /usr/lib/libsasl2.so.2 (0x1ca3d000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libgnutls.so.26 =&gt; /usr/lib/libgnutls.so.26 (0x1eb4b000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libkrb5.so.3 =&gt; /usr/lib/libkrb5.so.3 (0x14a7f000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libk5crypto.so.3 =&gt; /usr/lib/libk5crypto.so.3 (0x19f18000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libcom_err.so.2 =&gt; /lib/libcom_err.so.2 (0x13a74000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libkrb5support.so.0 =&gt; /usr/lib/libkrb5support.so.0 (0x0c97e000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libkeyutils.so.1 =&gt; /lib/libkeyutils.so.1 (0x0d073000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libtasn1.so.3 =&gt; /usr/lib/libtasn1.so.3 (0x0b5c2000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libgcrypt.so.11 =&gt; /lib/libgcrypt.so.11 (0x09524000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libgpg-error.so.0 =&gt; /lib/libgpg-error.so.0 (0x07565000)</div></div>
<p><h2><strong>3. Debugging Info</strong></h2>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ sudo gdb ./httpd<br />
<br />
GNU gdb (GDB) 7.1-ubuntu<br />
Copyright (C) 2010 Free Software Foundation, Inc.<br />
License GPLv3+: GNU GPL version 3 or later &lt;http://gnu.org/licenses/gpl.html&gt;<br />
This is free software: you are free to change and redistribute it.<br />
There is NO WARRANTY, to the extent permitted by law. &nbsp;Type &quot;show copying&quot;<br />
and &quot;show warranty&quot; for details.<br />
This GDB was configured as &quot;i486-linux-gnu&quot;.<br />
For bug reporting instructions, please see:<br />
&lt;http://www.gnu.org/software/gdb/bugs/&gt;...<br />
Reading symbols from /home/apache-2.2.2/bin/httpd...done.<br />
<br />
(gdb) b ap_process_request<br />
Breakpoint 1 at 0x80b2409: file http_request.c, line 252.<br />
(gdb) run -X -d /home/apache<br />
Starting program: /home/apache-2.2.2/bin/httpd -X -d /home/apache<br />
[Thread debugging using libthread_db enabled]<br />
<br />
Breakpoint 1, ap_process_request (r=0x831e390) at http_request.c:252<br />
252 &nbsp; &nbsp; &nbsp; &nbsp; if (ap_extended_status)<br />
(gdb) n<br />
235 &nbsp; &nbsp; {<br />
(gdb) n<br />
252 &nbsp; &nbsp; &nbsp; &nbsp; if (ap_extended_status)<br />
(gdb) n<br />
254 &nbsp; &nbsp; &nbsp; &nbsp; access_status = ap_run_quick_handler(r, 0); &nbsp;/* Not a look-up request */<br />
(gdb) n<br />
255 &nbsp; &nbsp; &nbsp; &nbsp; if (access_status == DECLINED) {<br />
(gdb) n<br />
256 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; access_status = ap_process_request_internal(r);<br />
(gdb) n<br />
257 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (access_status == OK) {<br />
(gdb) n<br />
258 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; access_status = ap_invoke_handler(r);<br />
(gdb) n<br />
<br />
Program received signal SIGSEGV, Segmentation fault.<br />
0x0079b611 in php_handler (r=0x831e390)<br />
&nbsp; &nbsp; at /home/kawasaki/src/php/php-5.3.3/sapi/apache2handler/sapi_apache2.c:550<br />
550 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conf = ap_get_module_config(r-&gt;per_dir_config, &amp;php5_module);<br />
(gdb) n<br />
<br />
(gdb) bt<br />
#0 &nbsp;0x0079b611 in php_handler (r=0x831e390)<br />
&nbsp; &nbsp; at /home/kawasaki/src/php/php-5.3.3/sapi/apache2handler/sapi_apache2.c:550<br />
#1 &nbsp;0x0807aa47 in ap_run_handler (r=0x831e390) at config.c:157<br />
#2 &nbsp;0x0807db31 in ap_invoke_handler (r=0x831e390) at config.c:371<br />
#3 &nbsp;0x080b2578 in ap_process_request (r=0x831e390) at http_request.c:258<br />
#4 &nbsp;0x080af81e in ap_process_http_connection (c=0x8314348) at http_core.c:172<br />
#5 &nbsp;0x080817c7 in ap_run_process_connection (c=0x8314348) at connection.c:43<br />
#6 &nbsp;0x080cf1d4 in child_main (child_num_arg=&lt;value optimised out&gt;) at prefork.c:640<br />
#7 &nbsp;0x080cf434 in make_child (s=0x8109f78, slot=0) at prefork.c:680<br />
#8 &nbsp;0x080d01fa in ap_mpm_run (_pconf=0x81010a8, plog=0x814b1d0, s=0x8109f78)<br />
&nbsp; &nbsp; at prefork.c:956<br />
#9 &nbsp;0x0806872f in main (argc=135262496, argv=0x0) at main.c:717</div></div>
<p>参考: <a href="http://httpd.apache.org/dev/debugging.html#gdb">Apache Debugging Guide: Using gdb</a></p>
<p>落ちている箇所、php_handler (php-5.3.3/sapi/apache2handler/sapi_apache2.c:550)のソースコード</p>
<div class="codecolorer-container c mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000dd;">538</span> <span style="color: #993333;">static</span> <span style="color: #993333;">int</span> php_handler<span style="color: #009900;">&#40;</span>request_rec <span style="color: #339933;">*</span>r<span style="color: #009900;">&#41;</span><br />
<span style="color: #0000dd;">539</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #0000dd;">540</span> &nbsp; &nbsp; php_struct <span style="color: #339933;">*</span> <span style="color: #993333;">volatile</span> ctx<span style="color: #339933;">;</span><br />
<span style="color: #0000dd;">541</span> &nbsp; &nbsp; <span style="color: #993333;">void</span> <span style="color: #339933;">*</span>conf<span style="color: #339933;">;</span><br />
<span style="color: #0000dd;">542</span> &nbsp; &nbsp; apr_bucket_brigade <span style="color: #339933;">*</span> <span style="color: #993333;">volatile</span> brigade<span style="color: #339933;">;</span><br />
<span style="color: #0000dd;">543</span> &nbsp; &nbsp; apr_bucket <span style="color: #339933;">*</span>bucket<span style="color: #339933;">;</span><br />
<span style="color: #0000dd;">544</span> &nbsp; &nbsp; apr_status_t rv<span style="color: #339933;">;</span><br />
<span style="color: #0000dd;">545</span> &nbsp; &nbsp; request_rec <span style="color: #339933;">*</span> <span style="color: #993333;">volatile</span> parent_req <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span><br />
<span style="color: #0000dd;">546</span> &nbsp; &nbsp; TSRMLS_FETCH<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #0000dd;">547</span><br />
<span style="color: #0000dd;">548</span> <span style="color: #339933;">#define PHPAP_INI_OFF php_apache_ini_dtor(r, parent_req TSRMLS_CC);</span><br />
<span style="color: #0000dd;">549</span><br />
<span style="color: #0000dd;">550</span> &nbsp; &nbsp; conf <span style="color: #339933;">=</span> ap_get_module_config<span style="color: #009900;">&#40;</span>r<span style="color: #339933;">-&gt;</span>per_dir_config<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>php5_module<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #0000dd;">551</span><br />
<span style="color: #0000dd;">552</span> &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* apply_config() needs r in some cases, so allocate server_context early */</span><br />
<span style="color: #0000dd;">553</span> &nbsp; &nbsp; ctx <span style="color: #339933;">=</span> SG<span style="color: #009900;">&#40;</span>server_context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #0000dd;">554</span> &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>ctx <span style="color: #339933;">==</span> NULL <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>ctx <span style="color: #339933;">&amp;&amp;</span> ctx<span style="color: #339933;">-&gt;</span>request_processed <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>strcmp<span style="color: #009900;">&#40;</span>r<span style="color: #339933;">-&gt;</span>protocol<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;INCLUDED&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #0000dd;">555</span> normal<span style="color: #339933;">:</span><br />
<span style="color: #0000dd;">556</span> &nbsp; &nbsp; &nbsp; &nbsp; ctx <span style="color: #339933;">=</span> SG<span style="color: #009900;">&#40;</span>server_context<span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> apr_pcalloc<span style="color: #009900;">&#40;</span>r<span style="color: #339933;">-&gt;</span>pool<span style="color: #339933;">,</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>ctx<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #0000dd;">557</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* register a cleanup so we clear out the SG(server_context)<br />
558 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* after each request. Note: We pass in the pointer to the<br />
559 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* server_context in case this is handled by a different thread.<br />
560 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
<span style="color: #0000dd;">561</span> &nbsp; &nbsp; &nbsp; &nbsp; apr_pool_cleanup_register<span style="color: #009900;">&#40;</span>r<span style="color: #339933;">-&gt;</span>pool<span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;</span>SG<span style="color: #009900;">&#40;</span>server_context<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> php_server_context_cleanup<span style="color: #339933;">,</span> apr_pool_cleanup_null<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #0000dd;">562</span> &nbsp; &nbsp; &nbsp; &nbsp; ctx<span style="color: #339933;">-&gt;</span>r <span style="color: #339933;">=</span> r<span style="color: #339933;">;</span><br />
<span style="color: #0000dd;">563</span> &nbsp; &nbsp; &nbsp; &nbsp; ctx <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* May look weird to null it here, but it is to catch the right case in the first_try later on */</span><br />
<span style="color: #0000dd;">564</span> &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #0000dd;">565</span> &nbsp; &nbsp; &nbsp; &nbsp; parent_req <span style="color: #339933;">=</span> ctx<span style="color: #339933;">-&gt;</span>r<span style="color: #339933;">;</span><br />
<span style="color: #0000dd;">566</span> &nbsp; &nbsp; &nbsp; &nbsp; ctx<span style="color: #339933;">-&gt;</span>r <span style="color: #339933;">=</span> r<span style="color: #339933;">;</span><br />
<span style="color: #0000dd;">567</span> &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #0000dd;">568</span> &nbsp; &nbsp; apply_config<span style="color: #009900;">&#40;</span>conf<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>php5 モジュールの設定情報読み込み時にSegmentation fault(11)でApacheがCrashしている。 理由がわからない。とりあえず調査はここで止め、Apacheの設定ファイルからはphp5 モジュールのロード設定をはずしている。 早まった考えかもしれないがPHPを使うのやめてしまおうかと思っている今日この頃。PHPなんて。。</p>
<p>おわり</p>
<p><h2><strong>追記 2010.12.05</strong></h2>
<p>Apache-2.2.2、PHP-5.3.3共にアンインストールして再インストールしたところ問題なく動いてしまった。evidenceを集め、問題を特定する、それしかないと思い込み（だらだらと）調査していたのでとりあえず再インストールしてみる選択肢は頭になかった。結論として、（素人ぽくてアレなんだけど）困ったときは再インストールしろ &#8211; ということだ。 </p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http://yk55.com/blog/2010/11/30/php5apache2_segmentation_fault_under_ubuntu/&amp;layout=button_count&amp;show_faces=1&amp;width=450&amp;action=like&amp;colorscheme=light&amp;font=arial" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:25px"></iframe>]]></content:encoded>
			<wfw:commentRss>http://yk55.com/blog/2010/11/30/php5apache2_segmentation_fault_under_ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LibeventとAPRでイベント駆動型HTTPサーバを作成してみた</title>
		<link>http://yk55.com/blog/2010/04/30/eventdriven_http_server_vs_httpd/</link>
		<comments>http://yk55.com/blog/2010/04/30/eventdriven_http_server_vs_httpd/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 01:35:25 +0000</pubDate>
		<dc:creator>yoichi</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ab]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[apr]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[libevent]]></category>
		<category><![CDATA[memorypool]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[vs_httpd]]></category>

		<guid isPermaLink="false">http://yk55.com/blog/?p=319</guid>
		<description><![CDATA[イベント駆動型処理フレームワークの定番？であるlibevent(An event notification library)とAPR(Apache ProtableRuntime)を使ってイベント駆動型HTTPサーバを書いてみた。既にこの手の簡易HTTPサーバは書き尽くされてる感があり何ら目新しさはなく、若干車輪の再開発的なものになってしまっているのは否めないがそこは気にしないでlibeventが提供するイベント駆動型HTTP処理機能（evhttp）のサンプルの1つとして読んでいただきたく。ちなみにAPRは主にメモリプールのために使っている。 ソースコード &#8211; vs_httpd.c http://github.com/yokawasa/vs_httpd/ http://github.com/yokawasa/vs_httpd/blob/master/vs_httpd.c イベント駆動HTTP処理基本コード main @ vs_httpd.c struct evhttp *httpd; /* event driven http */ event_init&#40;&#41;; httpd = evhttp_start&#40;g_config-&#62;svr_addr, g_config-&#62;svr_port&#41;; evhttp_set_gencb&#40;httpd, main_request_handler, NULL&#41;; event_dispatch&#40;&#41;; evhttp_free&#40;httpd&#41;; event_initでlibeventライブラリの初期化処理。event_base_new()でもOK evhttp_start(address, port)でbindするアドレス、listenするポートを指定 evhttp_set_gencbでリクエストイベントが通知される度にコールされるコールバック関数(main_request_handler)を登録。 event_dispatchでイベントループを開始しイベント通知を開始 evhttp_freeで作成されたHTTPサーバリソースを開放 &#91;evhttp_set_gencbの定義 @ evhttp.h&#93; /** Set a callback for all requests that are not caught by specific callbacks [...]]]></description>
			<content:encoded><![CDATA[<p>イベント駆動型処理フレームワークの定番？である<a href="http://monkey.org/~provos/libevent/">libevent</a>(An event notification library)と<a href="http://apr.apache.org/">APR</a>(Apache ProtableRuntime)を使ってイベント駆動型HTTPサーバを書いてみた。既にこの手の簡易HTTPサーバは書き尽くされてる感があり何ら目新しさはなく、若干車輪の再開発的なものになってしまっているのは否めないがそこは気にしないでlibeventが提供するイベント駆動型HTTP処理機能（<strong>evhttp</strong>）のサンプルの1つとして読んでいただきたく。ちなみにAPRは主にメモリプールのために使っている。</p>
<p><h2><strong>ソースコード &#8211; vs_httpd.c</strong></h2>
<p><a href="http://github.com/yokawasa/vs_httpd/">http://github.com/yokawasa/vs_httpd/</a><br />
<a href="http://github.com/yokawasa/vs_httpd/blob/master/vs_httpd.c">http://github.com/yokawasa/vs_httpd/blob/master/vs_httpd.c</a></p>
<p><u>イベント駆動HTTP処理基本コード  main @ vs_httpd.c</u></p>
<div class="codecolorer-container c mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333;">struct</span> evhttp <span style="color: #339933;">*</span>httpd<span style="color: #339933;">;</span><br />
<br />
<span style="color: #808080; font-style: italic;">/* event driven http */</span><br />
event_init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
httpd <span style="color: #339933;">=</span> evhttp_start<span style="color: #009900;">&#40;</span>g_config<span style="color: #339933;">-&gt;</span>svr_addr<span style="color: #339933;">,</span> g_config<span style="color: #339933;">-&gt;</span>svr_port<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
evhttp_set_gencb<span style="color: #009900;">&#40;</span>httpd<span style="color: #339933;">,</span> main_request_handler<span style="color: #339933;">,</span> NULL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
event_dispatch<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
evhttp_free<span style="color: #009900;">&#40;</span>httpd<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<ul>
<li>event_initでlibeventライブラリの初期化処理。event_base_new()でもOK</li>
<li>evhttp_start(address, port)でbindするアドレス、listenするポートを指定</li>
<li>evhttp_set_gencbでリクエストイベントが通知される度にコールされるコールバック関数(main_request_handler)を登録。</li>
<li>event_dispatchでイベントループを開始しイベント通知を開始</li>
<li>evhttp_freeで作成されたHTTPサーバリソースを開放</li>
</ul>
<div class="codecolorer-container c mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&#91;</span>evhttp_set_gencbの定義 @ evhttp.<span style="color: #202020;">h</span><span style="color: #009900;">&#93;</span><br />
<span style="color: #808080; font-style: italic;">/** Set a callback for all requests that are not caught by specific callbacks */</span><br />
<span style="color: #993333;">void</span> evhttp_set_gencb<span style="color: #009900;">&#40;</span> <span style="color: #993333;">struct</span> evhttp <span style="color: #339933;">*,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">void</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">struct</span> evhttp_request <span style="color: #339933;">*,</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p><p>
<u>リクエスト処理用コールバック関数 main_request_handler @ vs_httpd.c</u></p>
<div class="codecolorer-container c mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333;">void</span> main_request_handler<span style="color: #009900;">&#40;</span><span style="color: #993333;">struct</span> evhttp_request <span style="color: #339933;">*</span>r<span style="color: #339933;">,</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span>args<span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; apr_status_t rv<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">struct</span> evbuffer <span style="color: #339933;">*</span>evbuf<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>path<span style="color: #339933;">,</span> <span style="color: #339933;">*</span>mimetype<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>complemented_path<span style="color: #339933;">,</span> <span style="color: #339933;">*</span>extbuf<span style="color: #339933;">,</span> <span style="color: #339933;">*</span>filebuf<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">int</span> filesize <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* check reqeust type. currently only suppoert GET */</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>r<span style="color: #339933;">-&gt;</span>type <span style="color: #339933;">!=</span> EVHTTP_REQ_GET<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; fprintf<span style="color: #009900;">&#40;</span>stdout<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;only support GET request <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; evhttp_send_error<span style="color: #009900;">&#40;</span>r<span style="color: #339933;">,</span> HTTP_BADREQUEST<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;only support GET request&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; path <span style="color: #339933;">=</span> apr_psprintf<span style="color: #009900;">&#40;</span>g_mem_pool<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;%s%s&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; g_config<span style="color: #339933;">-&gt;</span>doc_root<span style="color: #339933;">,</span> evhttp_request_uri<span style="color: #009900;">&#40;</span>r<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>g_config<span style="color: #339933;">-&gt;</span>verbose<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; fprintf<span style="color: #009900;">&#40;</span>stderr<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;req uri=%s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> evhttp_request_uri<span style="color: #009900;">&#40;</span>r<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; fprintf<span style="color: #009900;">&#40;</span>stderr<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;req path=%s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> path <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* file or dir existence check */</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>exists<span style="color: #009900;">&#40;</span>path<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>complemented_path<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>filesize<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; evhttp_send_error<span style="color: #009900;">&#40;</span>r<span style="color: #339933;">,</span> HTTP_NOTFOUND<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;file not found&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* file's extension check */</span><br />
&nbsp; &nbsp; mimetype <span style="color: #339933;">=</span> apr_pstrdup<span style="color: #009900;">&#40;</span>g_mem_pool<span style="color: #339933;">,</span> DEFAULT_MIME_TYPE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; extbuf <span style="color: #339933;">=</span> strrchr<span style="color: #009900;">&#40;</span>complemented_path<span style="color: #339933;">,</span><span style="color: #ff0000;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>extbuf<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">++</span>extbuf<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; mimetype <span style="color: #339933;">=</span> find_mime_type<span style="color: #009900;">&#40;</span>extbuf<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* file read */</span><br />
&nbsp; &nbsp; filebuf <span style="color: #339933;">=</span> apr_palloc<span style="color: #009900;">&#40;</span>g_mem_pool<span style="color: #339933;">,</span> filesize <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; apr_file_t <span style="color: #339933;">*</span>file <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; rv <span style="color: #339933;">=</span> apr_file_open<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>file<span style="color: #339933;">,</span> complemented_path<span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;APR_READ<span style="color: #339933;">|</span>APR_BINARY<span style="color: #339933;">,</span> APR_OS_DEFAULT<span style="color: #339933;">,</span> g_mem_pool<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>rv <span style="color: #339933;">!=</span> APR_SUCCESS<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; evhttp_send_error<span style="color: #009900;">&#40;</span>r<span style="color: #339933;">,</span> HTTP_SERVUNAVAIL<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;failed to open file&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; apr_size_t len <span style="color: #339933;">=</span> filesize<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; rv <span style="color: #339933;">=</span> apr_file_read<span style="color: #009900;">&#40;</span>file<span style="color: #339933;">,</span> filebuf<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>len<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>rv <span style="color: #339933;">!=</span> APR_SUCCESS<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; evhttp_send_error<span style="color: #009900;">&#40;</span>r<span style="color: #339933;">,</span> HTTP_SERVUNAVAIL<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;failed to read file&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; apr_file_close<span style="color: #009900;">&#40;</span>file<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>g_config<span style="color: #339933;">-&gt;</span>verbose<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; fprintf<span style="color: #009900;">&#40;</span>stderr<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;res mimetype=%s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> mimetype<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; fprintf<span style="color: #009900;">&#40;</span>stderr<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;res file size=%d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> len<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; fprintf<span style="color: #009900;">&#40;</span>stderr<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;res file output=%s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> filebuf<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; evbuf <span style="color: #339933;">=</span> evbuffer_new<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>evbuf<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; fprintf<span style="color: #009900;">&#40;</span>stderr<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;failed to create response buffer<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; evhttp_send_error<span style="color: #009900;">&#40;</span>r<span style="color: #339933;">,</span> HTTP_SERVUNAVAIL<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;failed to create response buffer&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; evhttp_add_header<span style="color: #009900;">&#40;</span>r<span style="color: #339933;">-&gt;</span>output_headers<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Content-Type&quot;</span><span style="color: #339933;">,</span>mimetype<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; evhttp_add_header<span style="color: #009900;">&#40;</span>r<span style="color: #339933;">-&gt;</span>output_headers<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Content-Length&quot;</span><span style="color: #339933;">,</span> apr_psprintf<span style="color: #009900;">&#40;</span>g_mem_pool<span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;%d&quot;</span><span style="color: #339933;">,</span>filesize<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; evbuffer_add<span style="color: #009900;">&#40;</span>evbuf<span style="color: #339933;">,</span> filebuf<span style="color: #339933;">,</span> len<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; evhttp_send_reply<span style="color: #009900;">&#40;</span>r<span style="color: #339933;">,</span> HTTP_OK<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #339933;">,</span> evbuf<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; evbuffer_free<span style="color: #009900;">&#40;</span>evbuf<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<ul>
<li>GETメソッド(EVHTTP_REQ_GET)のみ処理を行う</li>
<li>exists()でリクエストされたuri(evhttp_request_uri(r))がファイルまたはディレクトリとして存在するかをチェック</li>
<li>find_mime_typeでファイル拡張子に対応するMIME TYPEを取得。拡張子がなければデフォルトMIME TYPE application/ocet-stream。この部分の処理は600 行のCでCGIをサポートする軽量WEBサーバ<a href="http://www.ibm.com/developerworks/jp/web/library/wa-ltwebserv/">mattows</a>のコードを参考、流用。</li>
<li>APRの<a href="http://apr.apache.org/docs/apr/1.4/group__apr__file__io.html">ファイルI/Oハンドルライブラリ</a>でファイルの読み込み。画像等バイナリファイルのためにopen時にAPR_BINARYフラグを指定している</li>
<li>evhttp_add_headerでレスポンス用outputヘッダに&#8221;Content-Type&#8221;と&#8221;Content-Lenght&#8221;を指定</li>
<li>(struct evbuffe*)evbufに読み込んだファイルデータをボディデータとして書き込む</li>
<li>evhttp_send_replyでクライアントにレスポンス</li>
</ul>
<p><p>
<u>APRメモリプールの利用 @ vs_httpd.c</u><br />
これは本題からそれるが全体的な特徴としてメモリ管理はAPRの<a href="http://apr.apache.org/docs/apr/1.4/group__apr__pools.html">メモリプール</a>を利用しているのでここで軽く説明する。</p>
<div class="codecolorer-container c mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333;">static</span> apr_pool_t <span style="color: #339933;">*</span>g_mem_pool <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span><br />
apr_pool_create<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>g_mem_pool<span style="color: #339933;">,</span> NULL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
...<br />
<span style="color: #202020;">g_config</span> <span style="color: #339933;">=</span> apr_pcalloc<span style="color: #009900;">&#40;</span>g_mem_pool<span style="color: #339933;">,</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>httpsvr_config<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
path <span style="color: #339933;">=</span> apr_psprintf<span style="color: #009900;">&#40;</span>g_mem_pool<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;%s%s&quot;</span><span style="color: #339933;">,</span> g_config<span style="color: #339933;">-&gt;</span>doc_root<span style="color: #339933;">,</span> evhttp_request_uri<span style="color: #009900;">&#40;</span>r<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
mimetype <span style="color: #339933;">=</span> apr_pstrdup<span style="color: #009900;">&#40;</span>g_mem_pool<span style="color: #339933;">,</span> DEFAULT_MIME_TYPE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
filebuf <span style="color: #339933;">=</span> apr_palloc<span style="color: #009900;">&#40;</span>g_mem_pool<span style="color: #339933;">,</span> filesize <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
rv <span style="color: #339933;">=</span> apr_file_open<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>file<span style="color: #339933;">,</span> complemented_path<span style="color: #339933;">,</span> APR_READ<span style="color: #339933;">|</span>APR_BINARY<span style="color: #339933;">,</span> APR_OS_DEFAULT<span style="color: #339933;">,</span> g_mem_pool<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
...<br />
<span style="color: #202020;">apr_pool_destroy</span><span style="color: #009900;">&#40;</span>g_mem_pool<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<ul>
<li>apr_pool_createでメモリプールの作成 </li>
<li>apr_palloc、apr_psprintf, を使用して、メモリプールからメモリを確保します</li>
<li>apr_pool_destroyを使用して、メモリプールを破棄 </li>
</ul>
<p><h2><strong>ダウンロード、コンパイル、そしてテスト</strong></h2>
<p>git clone で<a href="http://github.com/yokawasa/vs_httpd/">vs_httpdのコード</a>を取得(リポジトリ複製)する。</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ git clone git@github.com:yokawasa/vs_httpd.git<br />
<br />
Initialized empty Git repository in /home/m/dev/github/t/vs_httpd/.git/<br />
remote: Counting objects: 11, done.<br />
remote: Compressing objects: 100% (11/11), done.<br />
remote: Total 11 (delta 0), reused 0 (delta 0)<br />
Receiving objects: 100% (11/11), 8.51 KiB, done.</div></div>
<p>libeventとaprヘッダへのインクルードや両ライブラリのリンクができるようにMakefileのパス調整を行う。もちろんlibeventとaprがインストール済みであることが前提。もしまだならばまずはlibeventとaprをインストールしましょ。</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ vi Makefile<br />
CFLAGS = -I&lt;libeventのincludeパス&gt; -I&lt;apacheのincludeパス -Wall -g<br />
LIBS = -L&lt;libeventのlibパス&gt; -levent -L&lt;apacheのlibパス&gt; -lapr-1</div></div>
<p>パス変更後にmakeを実行。これでvs_httpdバイナリの出来上がり。vs_httpdの使い方は次のとおり。</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ ./vs_httpd -h<br />
Usage: vs_httpd [-a address] [-p port] [-d documentroot]<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[-D] [-v] [-h]<br />
Options:<br />
&nbsp; -a address &nbsp; &nbsp; &nbsp;: define server address (default: &quot;0.0.0.0&quot;)<br />
&nbsp; -p port &nbsp; &nbsp; &nbsp; &nbsp; : define server port (default: 8080)<br />
&nbsp; -d documentroot : define document root (default: &quot;./&quot;) &nbsp;<br />
&nbsp; -D &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: daemonize option 0-off,1-on (default: 0)<br />
&nbsp; -v &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: verbose option 0-off,1-on (default: 0)<br />
&nbsp; -h &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: list available command line options (this page)</div></div>
<p>使い方の説明にあるようにオプションを指定しない場合はデフォルトサーバアドレス&#8221;0.0.0.0&#8243;、ポート番号 8080、ドキュメントルート &#8220;./&#8221;、デーモンモードOFF、VerboseモードOFFで起動される。尚、デフォルトインデックスファイルをindex.htmlとしているので http://hostname:port/path/のようにファイル名を指定しないでアクセスした場合はvs_httpdがドキュメントルート /path/配下のindex.htmlを表示させようとする。試しにvs_httpdをポート(8888)、ドキュメントルート(/home /vs_httpd/docs)、デーモンモードON、VerboseモードONで起動させてみる。</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ ./vs_httpd -p 8888 -d /home/vs_httpd/docs -D -v<br />
svr_addr=0.0.0.0<br />
svr_port=8888<br />
doc_root=/home/vs_httpd/docs<br />
verbose=1<br />
daemonize=1<br />
$ ※<br />
<br />
※ daemonized! fork成功、親プロセスからはexitで子プロセスに処理が移る</div></div>
<p>ページ表示テスト用にvs_httpd/pages下にhtml、css、jpegファイルを用意してあるのでこれらを/home/vs_httpd /docs配下に配置して実際にブラウザでindex.htmlを表示させてみる。成功すると以下のようなページが表示させる。</p>
<p><a href="http://www.flickr.com/photos/yk55/4563326293/" title="VSHTTPD by yoichi*, on Flickr"><img src="http://farm4.static.flickr.com/3214/4563326293_63624d58f8_o.jpg" width="680" height="335" alt="VSHTTPD" /></a></p>
<p><h2><strong>ベンチマーク結果</strong></h2>
<p><a href="http://httpd.apache.org/docs/2.0/programs/ab.html">ab(apache bench)</a>でベンチマークテストをしてみる。並列数100、リクエスト数10000。比較のためにapache2(mpm prefork)でもテストをしてみる。まずはvs_httpdのテスト結果。</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ ab -c 100 -n 10000 http://127.0.0.1:8888/<br />
<br />
Server Software: &nbsp; &nbsp; &nbsp; &nbsp;<br />
Server Hostname: &nbsp; &nbsp; &nbsp; &nbsp;127.0.0.1<br />
Server Port: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;8888<br />
<br />
Document Path: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/<br />
Document Length: &nbsp; &nbsp; &nbsp; &nbsp;285 bytes<br />
<br />
Concurrency Level: &nbsp; &nbsp; &nbsp;100<br />
Time taken for tests: &nbsp; 2.295104 seconds<br />
Complete requests: &nbsp; &nbsp; &nbsp;10000<br />
Failed requests: &nbsp; &nbsp; &nbsp; &nbsp;0<br />
Write errors: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0<br />
Total transferred: &nbsp; &nbsp; &nbsp;3490440 bytes<br />
HTML transferred: &nbsp; &nbsp; &nbsp; 2858550 bytes<br />
Requests per second: &nbsp; &nbsp;4357.10 [#/sec] (mean)<br />
Time per request: &nbsp; &nbsp; &nbsp; 22.951 [ms] (mean)<br />
Time per request: &nbsp; &nbsp; &nbsp; 0.230 [ms] (mean, across all concurrent requests)<br />
Transfer rate: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1484.90 [Kbytes/sec] received<br />
<br />
Connection Times (ms)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; min &nbsp;mean[+/-sd] median &nbsp; max<br />
Connect: &nbsp; &nbsp; &nbsp; &nbsp;0 &nbsp; &nbsp;5 &nbsp; 4.2 &nbsp; &nbsp; &nbsp;4 &nbsp; &nbsp; &nbsp;27<br />
Processing: &nbsp; &nbsp; 5 &nbsp; 17 &nbsp; 6.4 &nbsp; &nbsp; 15 &nbsp; &nbsp; &nbsp;46<br />
Waiting: &nbsp; &nbsp; &nbsp; &nbsp;1 &nbsp; 13 &nbsp; 6.5 &nbsp; &nbsp; 11 &nbsp; &nbsp; &nbsp;45<br />
Total: &nbsp; &nbsp; &nbsp; &nbsp; 10 &nbsp; 22 &nbsp; 7.0 &nbsp; &nbsp; 21 &nbsp; &nbsp; &nbsp;47<br />
<br />
Percentage of the requests served within a certain time (ms)<br />
&nbsp; 50% &nbsp; &nbsp; 21<br />
&nbsp; 66% &nbsp; &nbsp; 24<br />
&nbsp; 75% &nbsp; &nbsp; 26<br />
&nbsp; 80% &nbsp; &nbsp; 27<br />
&nbsp; 90% &nbsp; &nbsp; 32<br />
&nbsp; 95% &nbsp; &nbsp; 37<br />
&nbsp; 98% &nbsp; &nbsp; 41<br />
&nbsp; 99% &nbsp; &nbsp; 42<br />
&nbsp;100% &nbsp; &nbsp; 47 (longest request)</div></div>
<p>次にapache2(mpm prefork)でも同様のテストを行う。利用するページはvs_httpdと同じでテスト環境のprefork MPM設定値は次のとおり。</p>
<pre>
[prefork MPMの設定値]
StartServers          5
MinSpareServers       5
MaxSpareServers      10
MaxClients          150
MaxRequestsPerChild   0
</pre>
<p>以下、apache2のテスト結果。</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ ab -c 100 -n 10000 http://127.0.0.1/<br />
<br />
Server Software: &nbsp; &nbsp; &nbsp; &nbsp;Apache/2.2.2<br />
Server Hostname: &nbsp; &nbsp; &nbsp; &nbsp;127.0.0.1<br />
Server Port: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;80<br />
<br />
Document Path: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/<br />
Document Length: &nbsp; &nbsp; &nbsp; &nbsp;285 bytes<br />
<br />
Concurrency Level: &nbsp; &nbsp; &nbsp;100<br />
Time taken for tests: &nbsp; 3.580232 seconds<br />
Complete requests: &nbsp; &nbsp; &nbsp;10000<br />
Failed requests: &nbsp; &nbsp; &nbsp; &nbsp;0<br />
Write errors: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0<br />
Total transferred: &nbsp; &nbsp; &nbsp;5310000 bytes<br />
HTML transferred: &nbsp; &nbsp; &nbsp; 2850000 bytes<br />
Requests per second: &nbsp; &nbsp;2793.12 [#/sec] (mean)<br />
Time per request: &nbsp; &nbsp; &nbsp; 35.802 [ms] (mean)<br />
Time per request: &nbsp; &nbsp; &nbsp; 0.358 [ms] (mean, across all concurrent requests)<br />
Transfer rate: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1448.23 [Kbytes/sec] received<br />
<br />
Connection Times (ms)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; min &nbsp;mean[+/-sd] median &nbsp; max<br />
Connect: &nbsp; &nbsp; &nbsp; &nbsp;0 &nbsp; &nbsp;0 &nbsp; 0.8 &nbsp; &nbsp; &nbsp;0 &nbsp; &nbsp; &nbsp;10<br />
Processing: &nbsp; &nbsp; 8 &nbsp; 35 &nbsp; 7.4 &nbsp; &nbsp; 31 &nbsp; &nbsp; &nbsp;66<br />
Waiting: &nbsp; &nbsp; &nbsp; &nbsp;2 &nbsp; 34 &nbsp; 7.4 &nbsp; &nbsp; 31 &nbsp; &nbsp; &nbsp;66<br />
Total: &nbsp; &nbsp; &nbsp; &nbsp; 12 &nbsp; 35 &nbsp; 7.4 &nbsp; &nbsp; 31 &nbsp; &nbsp; &nbsp;66<br />
<br />
Percentage of the requests served within a certain time (ms)<br />
&nbsp; 50% &nbsp; &nbsp; 31<br />
&nbsp; 66% &nbsp; &nbsp; 36<br />
&nbsp; 75% &nbsp; &nbsp; 40<br />
&nbsp; 80% &nbsp; &nbsp; 43<br />
&nbsp; 90% &nbsp; &nbsp; 47<br />
&nbsp; 95% &nbsp; &nbsp; 50<br />
&nbsp; 98% &nbsp; &nbsp; 53<br />
&nbsp; 99% &nbsp; &nbsp; 54<br />
&nbsp;100% &nbsp; &nbsp; 66 (longest request)</div></div>
<p>単純すぎるベンチマークテストなのでアレなのですが、10000リクエストの処理時間だけをみるとvs_httpd(2.295104 seconds)のほうがapache2(3.580232 seconds)よりも約35%速いといえる。余計な処理はな何も行わないで静的ファイル処理に特化しているので速いのは当たり前なんだけど、うれしい。この世界、速いは美徳。</p>
<p>おわり。</p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http://yk55.com/blog/2010/04/30/eventdriven_http_server_vs_httpd/&amp;layout=button_count&amp;show_faces=1&amp;width=450&amp;action=like&amp;colorscheme=light&amp;font=arial" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:25px"></iframe>]]></content:encoded>
			<wfw:commentRss>http://yk55.com/blog/2010/04/30/eventdriven_http_server_vs_httpd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	<!-- google_ad_section_end --><!-- google_ad_section_start(weight=ignore) --></channel>
</rss>

