Apacheチューニング:メモリのサイジング。

最初に

$ ab -n 100 -c 100 URL

 

とやってサーバが落ちたので、落ちないように設定したい。

 

環境

CentOS:7.3
メモリ:1GB
Apache:2.4.6(yumからインストール)(Prefork)
PHP:5.4.16(yumからインストール)
WordPress:4.7.4

 

手順

大雑把な計算なんだろうけど、落ちなくなったからそれで良しとする。

  1. 最初にabを使って、全ての子プロセスに現時点でかけられる大雑把な負荷をかける。
    (自分の環境では、httpd起動時は子プロセス1個あたり約6MBの使用量だったが、
    負荷をかけた後は約36MBになったので、子プロセス1個あたり約40MBで計算した。)
  2. $ ps -eF | grep httpd | grep apache | grep -v grep 

    とやって、Apacheの子プロセス1個がどれだけメモリ使っているか調べる。
    子プロセス1個が使うメモリ量をAとする。
    全ての子プロセスが使うメモリ量をBとする。

  3. freeコマンドで未使用のメモリを調べる。
    未使用のメモリ量をCとする。
  4. Apacheの子プロセスで使えるメモリ量をDとすると、
    D = B + C とわかる。
  5. 次に許容範囲の子プロセスの数をEとすると、
    E = D / A とわかる。
  6. 後はhttpd.confに、
    StartServers E
    MinSpareServers E
    MaxSpareServers E
    MaxRequestWorkers E
    

    と書けば良い。
    ついでに

    Timeout 15
    KeepAlive off
    

    も付け加えた。

  7. 次にabを使ってテストしていく。

結果

少なくとも、

$ ab -n 100 -c 100 URL

では落ちなくなった。
topコマンドを見ると、
load averageは4.94あたりまで上がっていた。
メモリ使用量は50MB~100MBほど余裕があるけど、
CPU使用率が100%になった。
もっと早く表示されるようにするには、CPUを良くしないとダメかも。

abの結果

[foo@bar ~]$ ab -n 100 -c 100 http://foobar
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking foobar (be patient).....done


Server Software:        Apache
Server Hostname:        foobar
Server Port:            80

Document Path:          foobar
Document Length:        68307 bytes

Concurrency Level:      100
Time taken for tests:   25.404 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Total transferred:      6863400 bytes
HTML transferred:       6830700 bytes
Requests per second:    3.94 [#/sec] (mean)
Time per request:       25404.455 [ms] (mean)
Time per request:       254.045 [ms] (mean, across all concurrent requests)
Transfer rate:          263.83 [Kbytes/sec] received

Connection Times (ms)
min  mean[+/-sd] median   max
Connect:       48   84  21.0     86     120
Processing:   659 13784 7134.8  14960   24863
Waiting:      372 12790 7174.7  13952   24611
Total:        706 13869 7155.3  15046   24983

Percentage of the requests served within a certain time (ms)
50%  15046
66%  18110
75%  20983
80%  21142
90%  24031
95%  24324
98%  24982
99%  24983
100%  24983 (longest request)

 

コメント

タイトルとURLをコピーしました