BLOG | システム監視・サーバ監視・障害監視・ネットワーク監視・システム運用・MySQL・Web地図を提供

BLOG エントリ一覧

まず、「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は簡単に導入できました。)

mod_proxyの設定はこちら
squidの設定はこちら

そして、apache(素)の、有るディレクトリに画像(約3K)を 15,000個配置しました。

また、 mod_proxy、squidは、すべてapache(素)にリクエストを飛ばすように設定しました。

測定方法ですが、 「Web Application Stress Tool」を使用して、以下のパターンで

5,000のユニークなリクエストに対する計測を2回づつ行いました。

  1. apache(素)
  2. mod_proxy(ディスクキャッシュ)
  3. mod_proxy(メモリキャッシュ)
  4. squid(デフォルト ストアタイプufs)
  5. squid(ストアタイプcoss)

測定結果

まず、「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

 

関連会社インターオフィスのブログ記事を転載しています。

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ファイルなのでディレクトリが複数作られます。
この配下にオブジェクトが作られていきます。

 

関連会社インターオフィスのブログ記事を転載しています。

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回目)

CODE:

  1. # ab -n 1000 -c 100 http://192.168.1.118/image1/madonna.jpg
  2. This is ApacheBench, Version 2.0.41-dev &lt;$Revision: 1.141 $&gt; apache-2.0
  3. Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
  4. Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/
  5.  
  6. Benchmarking 192.168.1.118 (be patient)
  7. Completed 100 requests
  8. Completed 200 requests
  9. Completed 300 requests
  10. Completed 400 requests
  11. Completed 500 requests
  12. Completed 600 requests
  13. Completed 700 requests
  14. Completed 800 requests
  15. Completed 900 requests
  16. Finished 1000 requests
  17.  
  18. Server Software: Apache
  19. Server Hostname: 192.168.1.118
  20. Server Port: 80
  21.  
  22. Document Path: /image1/madonna.jpg
  23. Document Length: 6224340 bytes
  24.  
  25. Concurrency Level: 100
  26. Time taken for tests: 565.240794 seconds
  27. Complete requests: 1000
  28. Failed requests: 0
  29. Write errors: 0
  30. Total transferred: -2115411649 bytes
  31. HTML transferred: -2115784277 bytes
  32. Requests per second: 1.77 [#/sec] (mean)
  33. Time per request: 56524.078 [ms] (mean)
  34. Time per request: 565.241 [ms] (mean, across all concurrent requests)
  35. Transfer rate: -3654.78 [Kbytes/sec] received
  36.  
  37. Connection Times (ms)
  38. min mean[+/-sd] median max
  39. Connect: 3 797 492.7 904 3546
  40. Processing: 3430 53248 14751.2 52013 151676
  41. Waiting: 19 1086 965.3 914 5448
  42. Total: 3433 54045 14756.7 52926 152012
  43.  
  44. Percentage of the requests served within a certain time (ms)
  45. 50% 52926
  46. 66% 53639
  47. 75% 53858
  48. 80% 54012
  49. 90% 66280
  50. 95% 82861
  51. 98% 104489
  52. 99% 114783
  53. 100% 152012 (longest request)

■mod_mem_cache(2回目)

CODE:

  1. # ab -n 1000 -c 100 http://192.168.1.118/image1/madonna.jpg
  2. This is ApacheBench, Version 2.0.41-dev &lt;$Revision: 1.141 $&gt; apache-2.0
  3. Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
  4. Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/
  5.  
  6. Benchmarking 192.168.1.118 (be patient)
  7. Completed 100 requests
  8. Completed 200 requests
  9. Completed 300 requests
  10. Completed 400 requests
  11. Completed 500 requests
  12. Completed 600 requests
  13. Completed 700 requests
  14. Completed 800 requests
  15. Completed 900 requests
  16. Finished 1000 requests
  17.  
  18. Server Software: Apache/2.2.3
  19. Server Hostname: 192.168.1.118
  20. Server Port: 80
  21.  
  22. Document Path: /image1/madonna.jpg
  23. Document Length: 6224340 bytes
  24.  
  25. Concurrency Level: 100
  26. Time taken for tests: 541.216442 seconds
  27. Complete requests: 1000
  28. Failed requests: 0
  29. Write errors: 0
  30. Total transferred: 2039502188 bytes
  31. HTML transferred: 2039117838 bytes
  32. Requests per second: 1.85 [#/sec] (mean)
  33. Time per request: 54121.643 [ms] (mean)
  34. Time per request: 541.216 [ms] (mean, across all concurrent requests)
  35. Transfer rate: 3680.05 [Kbytes/sec] received
  36.  
  37. Connection Times (ms)
  38. min mean[+/-sd] median max
  39. Connect: 4 616 245.5 621 1066
  40. Processing: 47056 52330 1134.5 52406 58867
  41. Waiting: 3 620 313.8 608 2666
  42. Total: 47064 52946 1217.7 53016 58875
  43.  
  44. Percentage of the requests served within a certain time (ms)
  45. 50% 53016
  46. 66% 53472
  47. 75% 53631
  48. 80% 53705
  49. 90% 54034
  50. 95% 54405
  51. 98% 54774
  52. 99% 55301
  53. 100% 58875 (longest request)

「Requests per second」をみると、1回目よりキャッシュ作成コストがかからない分良くなっています。
■mod_disk_cache (1回目)

CODE:

  1. # ab -n 1000 -c 100 http://192.168.1.118/image1/madonna.jpg
  2. This is ApacheBench, Version 2.0.41-dev &lt;$Revision: 1.141 $&gt; apache-2.0
  3. Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
  4. Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/
  5.  
  6. Benchmarking 192.168.1.118 (be patient)
  7. Completed 100 requests
  8. Completed 200 requests
  9. Completed 300 requests
  10. Completed 400 requests
  11. Completed 500 requests
  12. Completed 600 requests
  13. Completed 700 requests
  14. Completed 800 requests
  15. Completed 900 requests
  16. Finished 1000 requests
  17.  
  18. Server Software: Apache
  19. Server Hostname: 192.168.1.118
  20. Server Port: 80
  21.  
  22. Document Path: /image1/madonna.jpg
  23. Document Length: 6224340 bytes
  24.  
  25. Concurrency Level: 100
  26. Time taken for tests: 563.948094 seconds
  27. Complete requests: 1000
  28. Failed requests: 0
  29. Write errors: 0
  30. Total transferred: -2083013024 bytes
  31. HTML transferred: -2083393028 bytes
  32. Requests per second: 1.77 [#/sec] (mean)
  33. Time per request: 56394.812 [ms] (mean)
  34. Time per request: 563.948 [ms] (mean, across all concurrent requests)
  35. Transfer rate: -3607.06 [Kbytes/sec] received
  36.  
  37. Connection Times (ms)
  38. min mean[+/-sd] median max
  39. Connect: 3 820 487.6 907 9282
  40. Processing: 14690 52816 11812.7 51971 131135
  41. Waiting: 29 1173 1222.0 916 7325
  42. Total: 14697 53636 11855.9 52881 131596
  43.  
  44. Percentage of the requests served within a certain time (ms)
  45. 50% 52881
  46. 66% 53513
  47. 75% 53818
  48. 80% 53898
  49. 90% 55288
  50. 95% 77010
  51. 98% 93809
  52. 99% 107308
  53. 100% 131596 (longest request)

■測定開始直後のI/Oレポート

CODE:

  1. # sar 1 10 -b
  2. Linux 2.6.18-8.el5xen (xen-centos5-2) 20070523
  3.  
  4. 151930秒 tps rtps wtps bread/s bwrtn/s
  5. 1519313932.32 0.00 3932.32 0.00 38488.89
  6. 15193214827.45 0.00 14827.45 0.00 123215.69
  7. 151933178.79 0.00 178.79 0.00 3078.79
  8. 151934192.08 0.00 192.08 0.00 2693.07
  9. 151935388.12 0.00 388.12 0.00 5528.71
  10. 1519364013.00 0.00 4013.00 0.00 34744.00
  11. 15193713776.00 2.00 13774.00 16.00 114408.00
  12. 151938145.54 0.00 145.54 0.00 2027.72
  13. 151939312.00 0.00 312.00 0.00 4480.00
  14. 151940585.00 0.00 585.00 0.00 7600.00
  15. 平均値:      3849.75 0.20 3849.55 1.60 33740.38

キャッシュを作成しています。ディスクの書き込みが発生しています。

■測定終了間際のI/Oレポート

CODE:

  1. # sar 1 10 -b
  2. Linux 2.6.18-8.el5xen (xen-centos5-2) 20070523
  3.  
  4. 152154秒 tps rtps wtps bread/s bwrtn/s
  5. 1521550.00 0.00 0.00 0.00 0.00
  6. 1521560.00 0.00 0.00 0.00 0.00
  7. 1521570.00 0.00 0.00 0.00 0.00
  8. 1521580.00 0.00 0.00 0.00 0.00
  9. 15215916.00 0.00 16.00 0.00 208.00
  10. 1522000.00 0.00 0.00 0.00 0.00
  11. 1522010.00 0.00 0.00 0.00 0.00
  12. 1522020.00 0.00 0.00 0.00 0.00
  13. 1522030.00 0.00 0.00 0.00 0.00
  14. 15220418.00 0.00 18.00 0.00 224.00
  15. 平均値:      3.39 0.00 3.39 0.00 43.11

キャッシュの作成も終わり、ページキャッシュに乗っているのでI/Oが発生していません。

■mod_disk_cache (2回目)

CODE:

  1. # ab -n 1000 -c 100 http://192.168.1.118/image1/madonna.jpg
  2. This is ApacheBench, Version 2.0.41-dev &lt;$Revision: 1.141 $&gt; apache-2.0
  3. Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
  4. Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/
  5.  
  6. Benchmarking 192.168.1.118 (be patient)
  7. Completed 100 requests
  8. Completed 200 requests
  9. Completed 300 requests
  10. Completed 400 requests
  11. Completed 500 requests
  12. Completed 600 requests
  13. Completed 700 requests
  14. Completed 800 requests
  15. Completed 900 requests
  16. Finished 1000 requests
  17.  
  18. Server Software: Apache/2.2.3
  19. Server Hostname: 192.168.1.118
  20. Server Port: 80
  21.  
  22. Document Path: /image1/madonna.jpg
  23. Document Length: 6224340 bytes
  24.  
  25. Concurrency Level: 100
  26. Time taken for tests: 564.10562 seconds
  27. Complete requests: 1000
  28. Failed requests: 0
  29. Write errors: 0
  30. Total transferred: -1987294130 bytes
  31. HTML transferred: -1987678482 bytes
  32. Requests per second: 1.77 [#/sec] (mean)
  33. Time per request: 56401.056 [ms] (mean)
  34. Time per request: 564.011 [ms] (mean, across all concurrent requests)
  35. Transfer rate: -3440.92 [Kbytes/sec] received
  36.  
  37. Connection Times (ms)
  38. min mean[+/-sd] median max
  39. Connect: 4 539 310.6 515 3545
  40. Processing: 49131 52397 1825.6 52310 86632
  41. Waiting: 4 477 299.9 431 3572
  42. Total: 50026 52937 1827.3 52796 87669
  43.  
  44. Percentage of the requests served within a certain time (ms)
  45. 50% 52796
  46. 66% 53060
  47. 75% 53299
  48. 80% 53442
  49. 90% 53753
  50. 95% 54111
  51. 98% 55382
  52. 99% 58398
  53. 100% 87669 (longest request)

「Requests per second」を見るかぎり1回目と同じですが、「Connection Times 」をみると良くなっているのがわかります。

■測定開始直後のI/Oレポート

CODE:

  1. # sar 1 10 -b
  2. Linux 2.6.18-8.el5xen (xen-centos5-2) 20070523
  3.  
  4. 152935秒 tps rtps wtps bread/s bwrtn/s
  5. 1529360.00 0.00 0.00 0.00 0.00
  6. 1529370.00 0.00 0.00 0.00 0.00
  7. 1529380.00 0.00 0.00 0.00 0.00
  8. 1529390.00 0.00 0.00 0.00 0.00
  9. 15294011.88 0.00 11.88 0.00 158.42
  10. 1529410.00 0.00 0.00 0.00 0.00
  11. 1529420.00 0.00 0.00 0.00 0.00
  12. 1529430.00 0.00 0.00 0.00 0.00
  13. 1529440.00 0.00 0.00 0.00 0.00
  14. 1529450.00 0.00 0.00 0.00 0.00
  15. 平均値: 1.20 0.00 1.20 0.00 15.95

ほんの少しの差ですが、メモリキャッシュに軍配があがりましたが、ページキャッシュに乗っているのでほぼ同じです。

■mod_mem_cacheのメモリ使用率

CODE:

  1. # free -m
  2. total       used       free     shared    buffers     cached
  3. Mem:           768        414        353          0         24        196
  4. -/+ buffers/cache:        192        575
  5. Swap:         1023          0       1023

残メモリ=353 + 24 + 196 = 573M

■mod_disk_cacheのメモリ使用率

CODE:

  1. free -m
  2. total       used       free     shared    buffers     cached
  3. Mem:           768        348        419          0         24        196
  4. -/+ buffers/cache:        127        641
  5. Swap:         1023          0       1023

残メモリ=419 + 24 + 196 = 639M

 

関連会社インターオフィスのブログ記事を転載しています。

CentOS5.0に付属のApacheに設定をします。
バージョンは2.2.3でした。

httpd.confに「Include conf.d/*.conf」がすでに記述してあるので、conf.d配下に外部ファイルとして定義します。

まず、mod_proxy.confの作成をします。

————————————————————–

ProxyRequests Off #フォワードプロキシ機能を無効にする

Order deny,allow
Allow from all

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

 

関連会社インターオフィスのブログ記事を転載しています。

UNIX系のシステムでは、ファイルの持つタイムスタンプ情報に「修正時間」(mtime)、「作成時間」(ctime)、「アクセス時間」(atime)
情報があります。

touchコマンドでは-mオプションでmtimeを、-aオプションでatimeを更新できます。

ls -l で mtime、ls -lc で ctime、ls -lu で atime を表示することができます。

CODE:

  1. # ls -l *.txt
  2. -rw-r–r– 1 root root 0  513 16:50 access.txt
  3. -rw-r–r– 1 root root 0  513 16:50 modify.txt
  4. # touch -a access.txt
  5. # touch -m modify.txt
  6. # ls -lu *.txt
  7. -rw-r–r– 1 root root 0  513 16:58 access.txt
  8. -rw-r–r– 1 root root 0  513 16:50 modify.txt
  9. # ls -l *.txt
  10. -rw-r–r– 1 root root 0  513 16:50 access.txt
  11. -rw-r–r– 1 root root 0  513 16:58 modify.txt

非常にアクセス負荷の高い静的コンテンツ用のWWWサーバの場合はこのatimeに対する更新を無くしてやることで、負荷を下げること
ができます。

アクセス対象のファイルはこうなっています。

CODE:

  1. # ls -l *.html
  2. -rw-r–r– 1 root root 44 1121  2004 index.html
  3. # ls -lu *.html
  4. -rw-r–r– 1 root root 44  5月  8 17:56 index.html

ここでabで性能を確認しました。

3回実施した上で後の2回が以下の通り。

CODE:

  1. /usr/local/apache2/bin/ab -n 10000 -c 100 http://stockholm/
  2.  
  3. # /usr/local/apache2/bin/ab -n 10000 -c 100 http://stockholm/
  4. This is ApacheBench, Version 2.0.40-dev &lt;$Revision: 1.146 $&gt; apache-2.0
  5. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
  6. Copyright 2006 The Apache Software Foundation, http://www.apache.org/
  7.  
  8. Benchmarking stockholm (be patient)
  9. Completed 1000 requests
  10. Completed 2000 requests
  11. Completed 3000 requests
  12. Completed 4000 requests
  13. Completed 5000 requests
  14. Completed 6000 requests
  15. Completed 7000 requests
  16. Completed 8000 requests
  17. Completed 9000 requests
  18. Finished 10000 requests
  19.  
  20. Server Software:        Apache/2.2.4
  21. Server Hostname:        stockholm
  22. Server Port:            80
  23.  
  24. Document Path:          /
  25. Document Length:        44 bytes
  26.  
  27. Concurrency Level:      100
  28. Time taken for tests:   11.277795 seconds
  29. Complete requests:      10000
  30. Failed requests:        0
  31. Write errors:           0
  32. Total transferred:      2617830 bytes
  33. HTML transferred:       441320 bytes
  34. Requests per second:    886.70 [#/sec] (mean)
  35. Time per request:       112.778 [ms] (mean)
  36. Time per request:       1.128 [ms] (mean, across all concurrent requests)
  37. Transfer rate:          226.64 [Kbytes/sec] received
  38.  
  39. Connection Times (ms)
  40. min  mean[+/-sd] median   max
  41. Connect:        0   10  10.1      8      65
  42. Processing:    17  100  16.9    100     694
  43. Waiting:       16   72  25.6     79     658
  44. Total:         17  111  20.4    109     713
  45.  
  46. Percentage of the requests served within a certain time (ms)
  47. 50%    109
  48. 66%    114
  49. 75%    118
  50. 80%    121
  51. 90%    131
  52. 95%    139
  53. 98%    147
  54. 99%    154
  55. 100%    713 (longest request)
  56. # /usr/local/apache2/bin/ab -n 10000 -c 100 http://stockholm/
  57. This is ApacheBench, Version 2.0.40-dev &lt;$Revision: 1.146 $&gt; apache-2.0
  58. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
  59. Copyright 2006 The Apache Software Foundation, http://www.apache.org/
  60.  
  61. Benchmarking stockholm (be patient)
  62. Completed 1000 requests
  63. Completed 2000 requests
  64. Completed 3000 requests
  65. Completed 4000 requests
  66. Completed 5000 requests
  67. Completed 6000 requests
  68. Completed 7000 requests
  69. Completed 8000 requests
  70. Completed 9000 requests
  71. Finished 10000 requests
  72.  
  73. Server Software:        Apache/2.2.4
  74. Server Hostname:        stockholm
  75. Server Port:            80
  76.  
  77. Document Path:          /
  78. Document Length:        44 bytes
  79.  
  80. Concurrency Level:      100
  81. Time taken for tests:   11.428654 seconds
  82. Complete requests:      10000
  83. Failed requests:        0
  84. Write errors:           0
  85. Total transferred:      2610000 bytes
  86. HTML transferred:       440000 bytes
  87. Requests per second:    874.99 [#/sec] (mean)
  88. Time per request:       114.287 [ms] (mean)
  89. Time per request:       1.143 [ms] (mean, across all concurrent requests)
  90. Transfer rate:          222.95 [Kbytes/sec] received
  91.  
  92. Connection Times (ms)
  93. min  mean[+/-sd] median   max
  94. Connect:        0   42  30.3     41     104
  95. Processing:    25   70  18.0     68     117
  96. Waiting:        1   39  24.8     38     108
  97. Total:         25  113  17.1    113     217
  98.  
  99. Percentage of the requests served within a certain time (ms)
  100. 50%    113
  101. 66%    120
  102. 75%    126
  103. 80%    129
  104. 90%    136
  105. 95%    140
  106. 98%    144
  107. 99%    145
  108. 100%    217 (longest request)

Requests per second: 880.845 (平均)

index.htmlのタイムスタンプは以下の通りで確かに
atimeは更新されています。

CODE:

  1. # ls -l *.html
  2. -rw-r–r– 1 root root 44 1121  2004 index.html
  3. # ls -lu *.html
  4. -rw-r–r– 1 root root 44  513 17:08 index.html

atimeの更新は、/etc/fstabのマウントオプションとして「noatime」を指定することで無効化できる。

LABEL=/ / ext3 defaults,noatime 1 1

atimeの更新を無効化すると、mountコマンドで「noatime」と表示されます。

$ mount
/dev/hda1 on / type ext3 (rw,noatime)
(省略)

上記を設定した上で、再度以下を実施しました。

CODE:

  1. # /usr/local/apache2/bin/ab -n 10000 -c 100 http://stockholm/
  2. This is ApacheBench, Version 2.0.40-dev &lt;$Revision: 1.146 $&gt; apache-2.0
  3. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
  4. Copyright 2006 The Apache Software Foundation, http://www.apache.org/
  5.  
  6. Benchmarking stockholm (be patient)
  7. Completed 1000 requests
  8. Completed 2000 requests
  9. Completed 3000 requests
  10. Completed 4000 requests
  11. Completed 5000 requests
  12. Completed 6000 requests
  13. Completed 7000 requests
  14. Completed 8000 requests
  15. Completed 9000 requests
  16. Finished 10000 requests
  17.  
  18. Server Software:        Apache/2.2.4
  19. Server Hostname:        stockholm
  20. Server Port:            80
  21.  
  22. Document Path:          /
  23. Document Length:        44 bytes
  24.  
  25. Concurrency Level:      100
  26. Time taken for tests:   11.135027 seconds
  27. Complete requests:      10000
  28. Failed requests:        0
  29. Write errors:           0
  30. Total transferred:      2610000 bytes
  31. HTML transferred:       440000 bytes
  32. Requests per second:    898.07 [#/sec] (mean)
  33. Time per request:       111.350 [ms] (mean)
  34. Time per request:       1.114 [ms] (mean, across all concurrent requests)
  35. Transfer rate:          228.83 [Kbytes/sec] received
  36.  
  37. Connection Times (ms)
  38. min  mean[+/-sd] median   max
  39. Connect:        0    0   1.4      0      24
  40. Processing:    11  110 367.6     82    9107
  41. Waiting:       11   90 125.6     82    8169
  42. Total:         11  110 367.6     82    9107
  43.  
  44. Percentage of the requests served within a certain time (ms)
  45. 50%     82
  46. 66%     83
  47. 75%     84
  48. 80%     84
  49. 90%     92
  50. 95%    106
  51. 98%    109
  52. 99%    747
  53. 100%   9107 (longest request)
  54. # /usr/local/apache2/bin/ab -n 10000 -c 100 http://stockholm/
  55. This is ApacheBench, Version 2.0.40-dev &lt;$Revision: 1.146 $&gt; apache-2.0
  56. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
  57. Copyright 2006 The Apache Software Foundation, http://www.apache.org/
  58.  
  59. Benchmarking stockholm (be patient)
  60. Completed 1000 requests
  61. Completed 2000 requests
  62. Completed 3000 requests
  63. Completed 4000 requests
  64. Completed 5000 requests
  65. Completed 6000 requests
  66. Completed 7000 requests
  67. Completed 8000 requests
  68. Completed 9000 requests
  69. Finished 10000 requests
  70.  
  71. Server Software:        Apache/2.2.4
  72. Server Hostname:        stockholm
  73. Server Port:            80
  74.  
  75. Document Path:          /
  76. Document Length:        44 bytes
  77.  
  78. Concurrency Level:      100
  79. Time taken for tests:   11.79239 seconds
  80. Complete requests:      10000
  81. Failed requests:        0
  82. Write errors:           0
  83. Total transferred:      2610000 bytes
  84. HTML transferred:       440000 bytes
  85. Requests per second:    902.59 [#/sec] (mean)
  86. Time per request:       110.792 [ms] (mean)
  87. Time per request:       1.108 [ms] (mean, across all concurrent requests)
  88. Transfer rate:          229.98 [Kbytes/sec] received
  89.  
  90. Connection Times (ms)
  91. min  mean[+/-sd] median   max
  92. Connect:        0    0   1.4      0      24
  93. Processing:    11  109 294.7     89    9563
  94. Waiting:       11   96 152.2     88    9563
  95. Total:         11  109 294.7     89    9563
  96.  
  97. Percentage of the requests served within a certain time (ms)
  98. 50%     89
  99. 66%     90
  100. 75%     91
  101. 80%     92
  102. 90%     94
  103. 95%    104
  104. 98%    110
  105. 99%    693
  106. 100%   9563 (longest request)

Requests per second: 900.33 (平均)

1%と非常にわずかですが確かにチューニング効果はあるようです。
実際にatimeが必要になる局面が想定できないなら、やってみても
良い気がします。

それと確かにatimeは更新されていません。

CODE:

  1. # ls -lu *.html
  2. -rw-r–r– 1 root root 44  513 17:08 index.html

※この調査はCentOS5+apache2.2.4で実施しました。
サーバのスペックはかなり低いものです。

 

関連会社インターオフィスのブログ記事を転載しています。