<?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>Web活メモ帳 &#187; APC</title>
	<atom:link href="http://blog.verygoodtown.com/tag/apc/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.verygoodtown.com</link>
	<description>WEB開発者が使える世界の情報を発信します。</description>
	<lastBuildDate>Thu, 09 Feb 2012 02:01:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>CentOSにAPCをインストールする方法</title>
		<link>http://blog.verygoodtown.com/2010/02/centos-apc-install-how-to/</link>
		<comments>http://blog.verygoodtown.com/2010/02/centos-apc-install-how-to/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 08:39:56 +0000</pubDate>
		<dc:creator>linja</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[サーバー関連]]></category>
		<category><![CDATA[ApacheBench]]></category>
		<category><![CDATA[APC]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[pecl]]></category>

		<guid isPermaLink="false">http://blog.verygoodtown.com/?p=1966</guid>
		<description><![CDATA[
APCはPHPの中間コードのキャッシュや最適化を行う拡張モジュールです。基本的にPHPを使うサーバーに全て入れてよいようです。
本日とあるサーバーにインストールしたのでやり方をメモ。
環境
まずは環境ですが、CentO [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.verygoodtown.com/wordpress/wp-content/uploads/apc21.png" alt="apc2" title="apc2" width="600" height="180" class="alignnone size-full wp-image-1970" /><br />
APCはPHPの中間コードのキャッシュや最適化を行う拡張モジュールです。基本的にPHPを使うサーバーに全て入れてよいようです。<br />
本日とあるサーバーにインストールしたのでやり方をメモ。</p>
<h3>環境</h3>
<p>まずは環境ですが、CentOS 4.4 + PHP 5.1.6 です。</p>
<h3>事前準備</h3>
<p>まず、peclが入っているかどうか調べます。</p>
<pre class="code">
# pecl list-all apc
All packages:
=============
Package            Latest   Local
pecl/KTaglib       0.2.0           Library to edit audio properties and tags on MPEG and OGG files
pecl/FliteTTS                      Text to speech voice synthesis for PHP
pecl/Ovrimos                       Ovrimos interface
pecl/DTrace        1.0.3           A Solaris Dtrace provider
pecl/inclued       0.1.0           Clued-in about your inclueds
pecl/zookeeper     0.1.0           PHP extension for interfacing with Apache ZooKeeper
…
…
…
…
</pre>
<p>インストールされているパッケージが表示されれば、このSTEPは読み飛ばしてOKです。<br />
なければインストールます。</p>
<pre class="code">
# yum install -y php-pear
Setting up Install Process
Setting up repositories
update                    100% |=========================|  951 B    00:00
base                      100% |=========================| 1.1 kB    00:00
…
…
…
</pre>
<p>phpizeもインストールします。</p>
<pre class="code">
# yum install -y php-devel
</pre>
<p>apxsも無ければインストール</p>
<pre class="code">
# yum install -y httpd-devel
</pre>
<p>これでやっとpeclがインストールできます。</p>
<h3>インストール</h3>
<p>peclコマンドでインストールできます。</p>
<pre class="code">
# pecl install APC
</pre>
<p>無事にインストールが完了すると以下のようなメッセージがでます。</p>
<pre class="code">
Build process completed successfully
Installing '/var/tmp/pear-build-root/install-APC-3.0.19//usr/lib/php/modules/apc.so'
install ok: channel://pecl.php.net/APC-3.0.19
You should add "extension=apc.so" to php.ini
</pre>
<p>ふむふむ。php.iniに追加しろって事ですね。<br />
って事でphp.iniに以下の行を追加。場所はどこでもかまいません。</p>
<pre class="code">
extension=apc.so
</pre>
<p>iniファイルを編集したらapacheを再起動します。</p>
<p>これでとりあえず作業は完了です。<br />
phpinfoの画面でapcの項目があるか確認します。</p>
<p><img src="http://blog.verygoodtown.com/wordpress/wp-content/uploads/apc1.png" alt="apc" title="apc" width="600" height="660" class="alignnone size-full wp-image-1972" /></p>
<h3>アップグレード</h3>
<p>apcのアップグレードは以下のコマンドで。</p>
<pre class="code">
# pecl upgrade apc
</pre>
<h3>ベンチマーク</h3>
<p>ApacheBenchでどのくらい効果が変わったか測定します。<br />
1000件のリクエストを100の同時接続で計測した結果です。</p>
<pre class="code">
# ab -n 1000 -c 100 http://127.0.0.1/*****/test.php

Benchmarking 127.0.0.1 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Finished 1000 requests

Server Software:        Apache/2.0.63
Server Hostname:        127.0.0.1

Document Path:          /*****/test.php
Document Length:        1257 bytes

Concurrency Level:      100
Time taken for tests:   13.193656 seconds
Complete requests:      1000
Failed requests:        557
   (Connect: 0, Length: 557, Exceptions: 0)
Write errors:           0
Total transferred:      1897728 bytes
HTML transferred:       1504335 bytes
Requests per second:    75.79 [#/sec] (mean)
Time per request:       1319.366 [ms] (mean)
Time per request:       13.194 [ms] (mean, across all concurrent requests)
Transfer rate:          140.45 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    5  17.9      0      80
Processing:    74  923 879.0    498    5931
Waiting:       56  919 880.2    497    5930
Total:        102  929 877.3    502    5931

Percentage of the requests served within a certain time (ms)
  50%    502
  66%    974
  75%   1209
  80%   1371
  90%   2181
  95%   2667
  98%   3048
  99%   4531
 100%   5931 (longest request)
</pre>
<p>トータルで13秒でした。<br />
ふーむ。早くなってるんですかね。念のためapcを無効にして再度ベンチを図ってみました。</p>
<pre class="code">
# ab -n 1000 -c 100 http://127.0.0.1/*****/test.php

Benchmarking 127.0.0.1 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Finished 1000 requests

Server Software:        Apache/2.0.63
Server Hostname:        127.0.0.1
Server Port:            80

Document Path:          /*****/test.php
Document Length:        1257 bytes

Concurrency Level:      100
Time taken for tests:   32.801446 seconds
Complete requests:      1000
Failed requests:        3
   (Connect: 0, Length: 3, Exceptions: 0)
Write errors:           0
Total transferred:      1651341 bytes
HTML transferred:       1258341 bytes
Requests per second:    30.49 [#/sec] (mean)
Time per request:       3280.145 [ms] (mean)
Time per request:       32.801 [ms] (mean, across all concurrent requests)
Transfer rate:          49.14 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   62 171.8      0     599
Processing:   288 2895 1431.8   2741   22702
Waiting:        8 2886 1441.0   2740   22701
Total:        616 2958 1410.4   2760   23294

Percentage of the requests served within a certain time (ms)
  50%   2760
  66%   2896
  75%   2959
  80%   2987
  90%   3437
  95%   4084
  98%   6956
  99%   9495
 100%  23294 (longest request)
</pre>
<p>トータルで32秒でした。おお！19秒も違いますね。<br />
まさか、倍以上違うとは、、、</p>
<p>まだ入れてない方はぜひ。</p>
<h3>参考</h3>
<p>ちなみに高速化モジュールは他にも以下のようなものがあります。</p>
<ul>
<li>eAccelerator</li>
<li>PHPA(PHP Accelerator)</li>
<li>XCache</li>
</ul>
<p>今回はyumから入れたいという理由でAPCを採用しました。</p>
<p>導入にあたっては以下の記事を参考にさせていただきました。ありがとうございます。</p>
<p><a href="http://www.doyouphp.jp/tips/tips_apc.shtml" target="_blank">APC（Alternative PHP Cache）再び &#8211; Do You PHP?</a></p>
<p><a href="http://www.ideaxidea.com/archives/2009/01/php_apc.html" target="_blank">PHP（というかWordPress）高速化のためにAPC（Alternatice PHP Cache）入れた &#8211; IDEA*IDEA ～ 百式管理人のライフハックブログ</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.verygoodtown.com/2010/02/centos-apc-install-how-to/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

