LoginSignup
17
15

More than 5 years have passed since last update.

メモリ食い過ぎてたので、httpdのプロセスを制限した

Posted at

あらすじ

WordPressが重い

仮想PC内で立ち上げていたWordPressの応答が異常に悪かったり、データベース接続エラーが出たりしていた。

何度かmysqldを再起動しても治らない。

メモリが足りない 

MySQLのログを見てみると、メモリ不足のようだった。

mysqlのエラーログ
[Note] InnoDB: Highest supported file format is Barracuda.
[Note] InnoDB: The log sequence numbers 46304196 and 46304196 in ibdata files do not match the log sequence number 46522815 in the ib_logfiles!
[Note] InnoDB: Database was not shutdown normally!
[Note] InnoDB: Starting crash recovery.

freeコマンドでメモリの使用状況を見てみると、80%以上になっている。

コマンド打ってみた
# free

             total       used       free     shared    buffers     cached

Mem:       1020288     841068     179220         24       1432      23400

-/+ buffers/cache:     816236     204052

Swap:      2064380     595572    1468808

httpd立ち上がりすぎ!

プロセス見てみたら、大量のhttpdが立ち上がっていて、一つ一つはそれほどでもないが、多くのメモリを消費しているようだ。

プロセスチェック
[root@developer vhost_test]# ps aux | grep httpd

root      1367  0.0  0.0 313608   256 ?        Ss   09:35   0:01 /usr/sbin/httpd

apache    1487  0.1  3.4 354884 35444 ?        S    09:45   0:11 /usr/sbin/httpd

apache    1711  0.1  3.5 354584 35904 ?        S    09:48   0:08 /usr/sbin/httpd

apache    2218  0.1  3.5 383168 35752 ?        S    10:59   0:04 /usr/sbin/httpd

apache    2226  0.1  3.4 354596 35292 ?        S    10:59   0:05 /usr/sbin/httpd

apache    2689  0.1  3.1 343056 32224 ?        S    11:14   0:03 /usr/sbin/httpd

apache    2692  0.1  3.5 344336 36616 ?        S    11:14   0:03 /usr/sbin/httpd

apache    2694  0.1  3.0 343056 31588 ?        S    11:14   0:03 /usr/sbin/httpd

apache    2840  0.0  3.4 342412 35400 ?        S    11:22   0:02 /usr/sbin/httpd

apache    2844  0.0  3.4 342412 35108 ?        S    11:22   0:02 /usr/sbin/httpd

apache    2845  0.0  3.4 342412 35548 ?        S    11:22   0:01 /usr/sbin/httpd

apache    2846  0.0  3.2 342412 32984 ?        S    11:22   0:01 /usr/sbin/httpd

apache    2852  0.0  3.4 342412 35520 ?        S    11:22   0:01 /usr/sbin/httpd

apache    2853  0.0  3.1 342412 31676 ?        S    11:22   0:01 /usr/sbin/httpd

apache    2857  0.0  3.2 342412 33352 ?        S    11:22   0:01 /usr/sbin/httpd

apache    2859  0.0  3.2 342412 33032 ?        S    11:22   0:01 /usr/sbin/httpd

apache    2866  0.0  3.2 342412 32976 ?        S    11:22   0:01 /usr/sbin/httpd

apache    2868  0.0  3.2 342428 33400 ?        S    11:22   0:01 /usr/sbin/httpd

apache    2875  0.0  3.2 342412 33344 ?        S    11:22   0:01 /usr/sbin/httpd

apache    2879  0.0  3.2 342412 33028 ?        S    11:22   0:01 /usr/sbin/httpd

apache    2880  0.0  3.2 342412 32916 ?        S    11:22   0:01 /usr/sbin/httpd

root      3003  0.0  0.0 107456   940 pts/1    S+   12:03   0:00 grep httpd

httpd.confの設定を改める

プロセス立ち上がりすぎ!を解決するために方法を検索してみると、参考で取り上げたページが見つかる。

でも、そんなに問題でもなさそうな。

httpd.conf
vi /

##
## Server-Pool Size Regulation (MPM specific)
##

# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# ServerLimit: maximum value for MaxClients for the lifetime of the server
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule prefork.c>
StartServers       5
MinSpareServers    5
MaxSpareServers   10
ServerLimit      256
MaxClients       256
MaxRequestsPerChild  0
</IfModule>

詳しい説明は参考サイトを参照

プロセス数が少なくなるように設定した

StartServers  最初から立ち上がっているプロセス数 
8 -> 5

MaxSpareServers アイドル状態にいる子サーバの最大プロセス数
20 -> 10

MaxRequestsPerChild 個々のサーバが扱えるリクエスト数
4000 -> 0(無制限)

確かにプロセス数は少なくなった

これでWordPressが軽く・・・ならなかった。相変わらずデータベース接続エラーとか出るし。

メモリの使用状況を調べる。
減ってる・・・空き領域が。

メモリ使用状況
# free
             total       used       free     shared    buffers     cached
Mem:       1020288     895976     124312        296      13036      91176
-/+ buffers/cache:     791764     228524
Swap:      2064380          0    2064380

確かにapache

プロセスチェック
mysql     1304  0.1 45.7 1142252 466332 ?      Sl   12:26   0:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-

apache    1398  0.0  5.1 354552 52900 ?        S    12:26   0:00 /usr/sbin/httpd

apache    1399  0.0  5.3 366252 54456 ?        S    12:26   0:00 /usr/sbin/httpd

apache    1400  0.0  5.1 354808 52600 ?        S    12:26   0:00 /usr/sbin/httpd

apache    1401  0.0  5.1 354808 52600 ?        S    12:26   0:00 /usr/sbin/httpd

apache    1402  0.0  5.1 354808 52600 ?        S    12:26   0:00 /usr/sbin/httpd

今度はMySQLがメモリ食い過ぎ

プロセスごとのメモリ使用状況を見たら・・・なんじゃこりゃ。

メモリ使用状況
# ps aux
mysql     1304  0.1 45.7 1142252 466332 ?      Sl   12:26   0:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-

apache    1398  0.0  5.1 354552 52900 ?        S    12:26   0:00 /usr/sbin/httpd

apache    1399  0.0  5.3 366252 54456 ?        S    12:26   0:00 /usr/sbin/httpd

apache    1400  0.0  5.1 354808 52600 ?        S    12:26   0:00 /usr/sbin/httpd

apache    1401  0.0  5.1 354808 52600 ?        S    12:26   0:00 /usr/sbin/httpd

apache    1402  0.0  5.1 354808 52600 ?        S    12:26   0:00 /usr/sbin/httpd

MySQLそのものが臭い。設定がよくなかったようだ。
対応内容は別の投稿にて。

参考

Apacheのチューニングメモ

17
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
15