まず、「apache(素) vs mod_proxy vs squid」と大げさなのですが、リバースプロキシをつかって、単純に静的コンテンツ(画像)を返すのは、どれが速い?また、そのついでにapache(素)も測定しました。
2台しかマシンの調達ができなかったので・・・
apche(素)として、1台にApache2.0をインストール、
mod_proxy(Apache2.0)、squid2.6は、Xen上にゲストOSを2ついれてそれぞれにインストールしました。OSは、すべてCentOS5.0です。(Xenは簡単に導入できました。)
そして、apache(素)の、有るディレクトリに画像(約3K)を 15,000個配置しました。
また、 mod_proxy、squidは、すべてapache(素)にリクエストを飛ばすように設定しました。
測定方法ですが、 「Web Application Stress Tool」を使用して、以下のパターンで
5,000のユニークなリクエストに対する計測を2回づつ行いました。
まず、「Number of hits」に着目して下さい。
TOOLのテスト時間を1秒としたので、各リクエストの内、1秒以内で返ってきたものが、この項目にカウントされています。(たぶん)
当たり前ですが、 mod_proxy、squidは、2回目は、キャッシュされたものを表示しているため数値が増えています。
mod_proxyに関しては、ディスク、メモリキャッシュともあまり変わりません。これは画像が、キャッシュされているためです。(メモリ、ディスクのキャッシュの比較はこちら)
squidは、cossは速いです。ページキャッシュに乗っかっているのでメモリキャッシュよりも良い結果が出ています。
また、デフォルトのストアタイプは、mod_proxyのディスクキャッシュとかわりません。 キャッシュが、1オブジェクトが1ファイルという事からくるのでしょう。
今回、apche(素)そのなのとおり、素なのですが、「mod_cache」をつかえばmod_proxy程度の結果は出るでしょう。互いの用途は違ってくるとは思いますが。
負荷をもっとかければ、差が顕著に現れると思います。
●1 – 1回目
Web Application Stress Tool Version:1.1.293.1
Number of test clients: 1
Number of hits: 3069
Requests per Second: 51.15
Socket Statistics
——————————————————————————–
Socket Connects: 3070
Total Bytes Sent (in KB): 709.51
Bytes Sent Rate (in KB/s): 11.83
Total Bytes Recv (in KB): 10505.62
Bytes Recv Rate (in KB/s): 175.09
●1 – 2回目
==================================================
Web Application Stress Tool Version:1.1.293.1
Number of test clients: 1
Number of hits: 3018
Requests per Second: 50.30
Socket Statistics
——————————————————————————–
Socket Connects: 3019
Total Bytes Sent (in KB): 697.70
Bytes Sent Rate (in KB/s): 11.63
Total Bytes Recv (in KB): 10332.77
Bytes Recv Rate (in KB/s): 172.22
●2 – 1回目
==================================================
Web Application Stress Tool Version:1.1.293.1
Number of test clients: 1
Number of hits: 2936
Requests per Second: 48.94
Socket Statistics
——————————————————————————–
Socket Connects: 2937
Total Bytes Sent (in KB): 678.73
Bytes Sent Rate (in KB/s): 11.31
Total Bytes Recv (in KB): 10169.93
Bytes Recv Rate (in KB/s): 169.53
●2 – 2回目
==================================================
Web Application Stress Tool Version:1.1.293.1
Number of test clients: 1
Number of hits: 3283
Requests per Second: 54.72
Socket Statistics
——————————————————————————–
Socket Connects: 3284
Total Bytes Sent (in KB): 759.04
Bytes Sent Rate (in KB/s): 12.65
Total Bytes Recv (in KB): 11429.63
Bytes Recv Rate (in KB/s): 190.51
●3 – 1回目
==================================================
Web Application Stress Tool Version:1.1.293.1
Number of test clients: 1
Number of hits: 3022
Requests per Second: 50.38
Socket Statistics
——————————————————————————–
Socket Connects: 3023
Total Bytes Sent (in KB): 698.63
Bytes Sent Rate (in KB/s): 11.65
Total Bytes Recv (in KB): 10464.28
Bytes Recv Rate (in KB/s): 174.44
●3 – 2回目
==================================================
Web Application Stress Tool Version:1.1.293.1
Number of test clients: 1
Number of hits: 3273
Requests per Second: 54.56
Socket Statistics
——————————————————————————–
Socket Connects: 3274
Total Bytes Sent (in KB): 756.72
Bytes Sent Rate (in KB/s): 12.62
Total Bytes Recv (in KB): 11543.46
Bytes Recv Rate (in KB/s): 192.44
●4 – 1回目
==================================================
Web Application Stress Tool Version:1.1.293.1
Number of test clients: 1
Number of hits: 2997
Requests per Second: 49.96
Socket Statistics
——————————————————————————–
Socket Connects: 2998
Total Bytes Sent (in KB): 692.84
Bytes Sent Rate (in KB/s): 11.55
Total Bytes Recv (in KB): 10627.54
Bytes Recv Rate (in KB/s): 177.17
●4 – 2回目
==================================================
Web Application Stress Tool Version:1.1.293.1
Number of test clients: 1
Number of hits: 3294
Requests per Second: 54.90
Socket Statistics
——————————————————————————–
Socket Connects: 3295
Total Bytes Sent (in KB): 761.58
Bytes Sent Rate (in KB/s): 12.69
Total Bytes Recv (in KB): 11692.82
Bytes Recv Rate (in KB/s): 194.89
●5 – 1回目
==================================================
Web Application Stress Tool Version:1.1.293.1
Number of test clients: 1
Number of hits: 3043
Requests per Second: 50.72
Socket Statistics
——————————————————————————–
Socket Connects: 3044
Total Bytes Sent (in KB): 703.49
Bytes Sent Rate (in KB/s): 11.73
Total Bytes Recv (in KB): 10788.85[/JAVA][/CODE][/XML]
Bytes Recv Rate (in KB/s): 179.84
●5 – 2回目 ==================================================
Web Application Stress Tool Version:1.1.293.1
Number of test clients: 1
Number of hits: 3410
Requests per Second: 56.85
Socket Statistics
——————————————————————————–
Socket Connects: 3411
Total Bytes Sent (in KB): 788.43
Bytes Sent Rate (in KB/s): 13.14
Total Bytes Recv (in KB): 12099.63
Bytes Recv Rate (in KB/s): 201.71
3月 03
CentOS5.0に付属のsquidに設定をします。
バージョンは、「Squid Cache: Version 2.6.STABLE6」。
COSSも使えます。
※COSSはSquid2.6から使えるようになったCyclic Object storage systemです。
COSSの場合、キャッシュオブジェクトが、1ファイルに納められるので、IOコストが軽減されます。
逆に以前のストアタイプの場合は、1キャッシュオブジェクト、1ファイルです。
まず、squid.confの設定をします。中身は、以下になります。
==================================================
cache_dir coss /var/spool/squid/coss 300 block-size=2048 max-size=500000
#cache_dir ufs /var/spool/squid 100 16 256 ===> デフォルトはこれ
cache_swap_log /var/spool/squid/%s
http_port 80 defaultsite=192.168.1.111
http_access allow all
cache_peer 192.168.1.111 parent 80 0 no-query originserver name=server_1
acl sites_server_1 dstdomain 192.168.1.111
cache_peer_access server_1 allow sites_server_1
==================================================
今回は、すべてのリクエストを「192.168.1.111」に転送するように設定しました。
squidを起動すると、cache_dirには、以下のようなファイル、ディレクトリができます。
■cossの場合
[root@xen-centos5-3 squid]# ls -lh
合計 301M
-rw——- 1 squid squid 300M 5月 22 13:20 coss
-rw-r—– 1 squid squid 192 5月 22 13:21 var.spool.squid.coss
1ファイルなので「coss」のみ。
■ufsの場合
[root@xen-centos5-3 squid]# ls -lh
合計 68K
drwxr-x— 258 squid squid 4.0K 5月 22 13:25 00
drwxr-x— 258 squid squid 4.0K 5月 22 13:25 01
drwxr-x— 258 squid squid 4.0K 5月 22 13:25 02
drwxr-x— 258 squid squid 4.0K 5月 22 13:25 03
drwxr-x— 258 squid squid 4.0K 5月 22 13:25 04
drwxr-x— 258 squid squid 4.0K 5月 22 13:25 05
drwxr-x— 258 squid squid 4.0K 5月 22 13:25 06
drwxr-x— 258 squid squid 4.0K 5月 22 13:25 07
drwxr-x— 258 squid squid 4.0K 5月 22 13:25 08
drwxr-x— 258 squid squid 4.0K 5月 22 13:25 09
drwxr-x— 258 squid squid 4.0K 5月 22 13:25 0A
drwxr-x— 258 squid squid 4.0K 5月 22 13:25 0B
drwxr-x— 258 squid squid 4.0K 5月 22 13:25 0C
drwxr-x— 258 squid squid 4.0K 5月 22 13:25 0D
drwxr-x— 258 squid squid 4.0K 5月 22 13:25 0E
drwxr-x— 258 squid squid 4.0K 5月 22 13:25 0F
-rw-r—– 1 squid squid 48 5月 22 13:25 var.spool.squid
1キャッシュオブジェクト、1ファイルなのでディレクトリが複数作られます。
この配下にオブジェクトが作られていきます。
3月 02
「mod_proxy によるリバース・プロキシの設定」で使用したマシンで、両者の性能を比較してみます。
worker MPMの設定以下のようにしました。
<IfModule worker.c>
StartServers 7
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 150
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>
※メモリキャッシュの単位が、プロセス毎なので、プロセス数が7より下回らないようにしました。
■mod_mem_cache(1回目)
■mod_mem_cache(2回目)
「Requests per second」をみると、1回目よりキャッシュ作成コストがかからない分良くなっています。
■mod_disk_cache (1回目)
■測定開始直後のI/Oレポート
キャッシュを作成しています。ディスクの書き込みが発生しています。
■測定終了間際のI/Oレポート
キャッシュの作成も終わり、ページキャッシュに乗っているのでI/Oが発生していません。
■mod_disk_cache (2回目)
「Requests per second」を見るかぎり1回目と同じですが、「Connection Times 」をみると良くなっているのがわかります。
■測定開始直後のI/Oレポート
ほんの少しの差ですが、メモリキャッシュに軍配があがりましたが、ページキャッシュに乗っているのでほぼ同じです。
■mod_mem_cacheのメモリ使用率
残メモリ=353 + 24 + 196 = 573M
■mod_disk_cacheのメモリ使用率
残メモリ=419 + 24 + 196 = 639M
3月 01
CentOS5.0に付属のApacheに設定をします。
バージョンは2.2.3でした。
httpd.confに「Include conf.d/*.conf」がすでに記述してあるので、conf.d配下に外部ファイルとして定義します。
まず、mod_proxy.confの作成をします。
————————————————————–
ProxyRequests Off #フォワードプロキシ機能を無効にする
ProxyPass / http://192.168.1.111/
ProxyPassReverse / http://192.168.1.111/
————————————————————–
今回は、すべてのリクエストを「192.168.1.111」転送するように設定しました。
次に、キャッシュの設定のためにmod_cache.confを作成します。
————————————————————–
<IfModule mod_cache.c>
#Last-Modified 日時が指定されていない ドキュメントでもキャッシュするように指定できます。
CacheIgnoreNoLastMod On
#ディスクキャッシュヲの場合
CacheEnable disk /
#メモリキャッシュヲ用の場合
# CacheEnable mem /
<IfModule mod_disk_cache.c>
CacheRoot “/var/cache/mod_proxy”
CacheDirLevels 1
CacheDirLength 3
</IfModule>
<IfModule mod_mem_cache.c>
MCacheSize 700000
MCacheMaxObjectCount 9000
MCacheMinObjectSize 1
MCacheMaxObjectSize 80000
MCacheMaxStreamingBuffer 80000
CacheIgnoreCacheControl On
CacheStorePrivate On
</IfModule>
</IfModule>
————————————————————–
※各ディレクティブの詳細は、こちら。
ちなみに、mod_mem_cacheは、プロセス毎にメモリを確保しキャッシュします。
デフォルトのMPMは、「prefork」。キャッシュを共有しないので、効率が悪いです。なので「worker」に変更します。
RPM版のApacheには、すでにインストールされているので、
/etc/sysconfig/httpdを以下のように変更すれば、workerで動作します。
HTTPD=/usr/sbin/httpd.worker
2月 26
UNIX系のシステムでは、ファイルの持つタイムスタンプ情報に「修正時間」(mtime)、「作成時間」(ctime)、「アクセス時間」(atime)
情報があります。
touchコマンドでは-mオプションでmtimeを、-aオプションでatimeを更新できます。
ls -l で mtime、ls -lc で ctime、ls -lu で atime を表示することができます。
非常にアクセス負荷の高い静的コンテンツ用のWWWサーバの場合はこのatimeに対する更新を無くしてやることで、負荷を下げること
ができます。
アクセス対象のファイルはこうなっています。
3回実施した上で後の2回が以下の通り。
index.htmlのタイムスタンプは以下の通りで確かに
atimeは更新されています。
atimeの更新は、/etc/fstabのマウントオプションとして「noatime」を指定することで無効化できる。
LABEL=/ / ext3 defaults,noatime 1 1
atimeの更新を無効化すると、mountコマンドで「noatime」と表示されます。
$ mount
/dev/hda1 on / type ext3 (rw,noatime)
(省略)
1%と非常にわずかですが確かにチューニング効果はあるようです。
実際にatimeが必要になる局面が想定できないなら、やってみても
良い気がします。
※この調査はCentOS5+apache2.2.4で実施しました。
サーバのスペックはかなり低いものです。
2月 25