LoginSignup
1
1

More than 5 years have passed since last update.

Apacheの子プロセスの数を減らす(raspberrypi用)

Last updated at Posted at 2015-08-31

参考

設定

  • RaspberryPiはスペックが低いため減らしておきたい。
10個居る
$ ps -ef | grep apache | grep www-data
www-data  5199   713  0  8月30 ?      00:00:01 /usr/sbin/apache2 -k start
www-data  5412   713  0  8月30 ?      00:00:03 /usr/sbin/apache2 -k start
www-data  5552   713  0  8月30 ?      00:00:00 /usr/sbin/apache2 -k start
www-data  5610   713  0  8月30 ?      00:00:00 /usr/sbin/apache2 -k start
www-data  5618   713  0  8月30 ?      00:00:00 /usr/sbin/apache2 -k start
www-data  5630   713  0  8月30 ?      00:00:00 /usr/sbin/apache2 -k start
www-data  5631   713  0  8月30 ?      00:00:00 /usr/sbin/apache2 -k start
www-data  5632   713  0  8月30 ?      00:00:00 /usr/sbin/apache2 -k start
www-data  5664   713  0  8月30 ?      00:00:00 /usr/sbin/apache2 -k start
www-data  7156   713  0  8月30 ?      00:00:00 /usr/sbin/apache2 -k start
/etc/apache2/mods-enabled/mpm_prefork.conf
  # 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
  # MaxRequestWorkers: maximum number of server processes allowed to start
  # MaxConnectionsPerChild: maximum number of requests a server process serves

  <IfModule mpm_prefork_module>
-   StartServers            5
-   MinSpareServers         5
-   MaxSpareServers         10
-   MaxRequestWorkers       150
-   MaxConnectionsPerChild  0
+   StartServers             4
+   MinSpareServers          4
+   MaxSpareServers          4
+   MaxRequestWorkers        4
+   MaxConnectionsPerChild   1000
  </IfModule>
  • apacheを再起動。
減ったことを確認
$ ps -ef | grep apache | grep www-data
www-data 13220 13199  0 05:56 ?        00:00:00 /usr/sbin/apache2 -k start
www-data 13221 13199  0 05:56 ?        00:00:00 /usr/sbin/apache2 -k start
www-data 13222 13199  0 05:56 ?        00:00:00 /usr/sbin/apache2 -k start
www-data 13223 13199  0 05:56 ?        00:00:00 /usr/sbin/apache2 -k start

Apache設定の確認

/usr/sbin/apachectl -V
  • Prefork か Worker かの判別ができる。通常Prefork

通常時のプロセス数把握しておく

mkdir -p $HOME/cron/apache_procs/
touch $HOME/cron/check_apache_procs.sh
$HOME/cron/check_apache_procs.sh
#!/bin/sh
LANG=C
set -eu

# PROCS=`ps -ef | grep http[d] | wc -l`
PROCS=`ps -ef | grep apache[2] | wc -l`
NOW=`date +'%H:%M'`

cd $HOME/cron/apache_procs/
echo "${NOW} ${PROCS}" >> `date -I`.txt
crontab -e
* * * * * /bin/sh $HOME/cron/check_apache_procs.sh
1
1
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
1
1