Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a dedicated server with 1GB of memory serving some wordpress sites, but happens when performing tests (ab: apache benmark, with -n 100 -c 10) to some of this wordpress, the server start to swap and then it's like dying...

So, my question is, how to tune apache and mysql for this purpose? I'm using mpm_worker in apache for php5

Any advice on tuning apache.conf and my.cnf files?

EDIT: I was trying to collect more data to post here, but as my server continues dying by swapping, I'll post whatevery I have now:

apache2.conf

<IfModule mpm_worker_module>
    StartServers          2
    MinSpareThreads      20
    MaxSpareThreads      50
    ThreadLimit          64
    ThreadsPerChild      25
    MaxClients           75
    MaxRequestsPerChild   0
</IfModule>

my.cnf (within [mysqld])

key_buffer_size         = 32M
max_allowed_packet      = 16M
thread_stack            = 192K
thread_cache_size       = 8
join_buffer_size        = 128K
myisam-recover          = BACKUP
max_connections         = 120
table_cache             = 128
max_heap_table_size     = 32M
tmp_table_size          = 32M
table_open_cache        = 128
query_cache_limit       = 1M
query_cache_size        = 16M
log_slow_queries        = /var/log/mysql/mysql-slow.log
long_query_time         = 2
log_queries_not_using_indexes = 1
expire_logs_days        = 10
max_binlog_size         = 100M

ps aux --sort -pcpu,-rss | head -n 30

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
www-data 11558 13.0  1.9 173280 20112 ?        R    13:59   0:00 /usr/lib/cgi-bin/php5
www-data 11529 14.0  3.6 190352 37192 ?        R    13:59   0:00 /usr/lib/cgi-bin/php5
www-data 11528 14.0  3.7 190784 37628 ?        R    13:59   0:00 /usr/lib/cgi-bin/php5
www-data 11526 16.5  3.9 192836 39580 ?        R    13:59   0:00 /usr/lib/cgi-bin/php5
svn       1909  4.2  0.3  91780  3628 ?        S    12:49   3:01 /usr/bin/svnserve --daemon --foreground -T -r /home/svn
mysql     7780  1.1  6.4 263812 64816 pts/1    Sl   13:43   0:11 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306
root       856  1.1  0.0      0     0 ?        D    12:48   0:49 [md3_resync]
root       325  0.5  0.0      0     0 ?        S    12:48   0:22 [md3_raid1]
www-data  1731  0.3  1.1 449516 11232 ?        Sl   12:49   0:13 /usr/sbin/apache2 -k start
www-data  1732  0.2  1.0 383548 10408 ?        Sl   12:49   0:12 /usr/sbin/apache2 -k start
bind      1244  0.0  1.0 125576 11096 ?        Ssl  12:48   0:02 /usr/sbin/named -u bind
root      1235  0.0  0.0   3864   300 ?        SNs  12:48   0:02 /usr/sbin/powernowd -q
postgres  1420  0.0  0.6 105560  6764 ?        S    12:48   0:01 /usr/lib/postgresql/8.4/bin/postgres -D /var/lib/postgresql/8.4/main -c config_file=/etc/postgresql/8.4/main/postgresql.conf
danikaze  5068  0.0  0.4  24512  4112 pts/1    Ss   13:17   0:00 -bash
root         1  0.0  0.0   8356   788 ?        Ss   12:48   0:00 init [2]
root      1143  0.0  0.2  41148  2636 ?        Sl   12:48   0:00 /usr/sbin/monit -c /etc/monit/monitrc -s /var/lib/monit/monit.state
danikaze  2778  0.0  0.4  24632  4216 pts/0    Ss   12:49   0:00 -bash
postgres  1535  0.0  0.2 105668  2860 ?        Ss   12:49   0:00 postgres: writer process
root        56  0.0  0.0      0     0 ?        S    12:48   0:00 [kswapd0]
danikaze  2777  0.0  0.1  70496  1816 ?        S    12:49   0:00 sshd: danikaze@pts/0
postgres  1536  0.0  0.1 105560  1584 ?        Ss   12:49   0:00 postgres: wal writer process
root      2529  0.0  0.0      0     0 ?        S    12:49   0:00 [flush-253:2]
root      1627  0.0  0.5  90628  5360 ?        Ss   12:49   0:00 /usr/sbin/apache2 -k start
root      1689  0.0  0.0  16780   804 ?        S    12:49   0:00 /usr/sbin/rotatelogs -l /home/***.com.log.%Y-%m-%d 86400
postgres  1538  0.0  0.1  77108  1516 ?        Ss   12:49   0:00 postgres: stats collector process
root       968  0.0  0.0      0     0 ?        S    12:48   0:00 [flush-253:1]
root      7639  0.0  0.1  13940  1484 pts/1    S    13:43   0:00 /bin/sh/usr/bin/mysqld_safe
ntp       1237  0.0  0.2  38340  2148 ?        Ss   12:48   0:00 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 105:106

free -m

             total       used       free     shared    buffers     cached
Mem:           986        769        216          0         37        532
-/+ buffers/cache:        199        787
Swap:         3827          0       3827

I will try to get data again when the server is swapping, but I don't know the reason of this, even if I stress the server with ab, only thing I get is use of CPU and MEM but no swap now I installed cache for wordpress... and still I get the server swapping and hanging in some moments :-/

Other thing: the server basically uses apache + mysql, even if there is also svnserver, proftpd and pgsql, they are almost no used.

share|improve this question
    
Please provide some more info like relevant parts of the apache configuration and output of top or similar –  Thomas Berger Oct 17 '12 at 16:59
    
Done! Now you have config info as well as ps and free output –  danikaze Oct 19 '12 at 12:07

1 Answer 1

Since you are using mpm_worker I would highly recommend using php5-fpm over mod_php.

In addition, 1GB is not a lot of RAM to be running even a slightly busy WordPress site. You should certainly increase your RAM if possible as that will provide your best performance increase. With more RAM you can ensure your MySQL indexes are cached, use APC, etc.

Running the MySQL Tuning Primer script will also help set a good baseline config for your MySQL to ensure you aren't wasting precious resources.

Also consider setting the vm.swappiness = 10 or 20 in your /etc/sysctl.conf to prevent early swapping from happening.

share|improve this answer
    
php5-fpm seems interesting. Anyway I want to know how to tune the mpm_worker (since I don't want to install other things right now) I know 1GB is not a lot of RAM, but it's what I can afford right now. Anyway I installed cache plugins so the use of php/mysql should be a lot less from now on. By the way, I ran the MySQL Tuning Primer script, but as my server is collapsing, I didn't have MySQL working for 48h. I'll try to post data as soon as possible. –  danikaze Oct 19 '12 at 12:07
    
Just be aware that any caching (e.g. APC) that you use also reduces the amount of available RAM. You could potentially reduce the amount of memory that is needed by Apache and PHP by disabling modules that you do not actually need. Naturally I cannot advise what you could disable as I do not know your environment but that would be the first place to look. The biggest parts about the MySQL tuning is your key_buffer and innodb_buffers settings. You could also avoid swapping by reducing the Apache MaxClients to a value that wouldn't exhaust your RAM. –  KayakJim Oct 19 '12 at 14:55
    
Don't worry. Wordpress cache plugin is based on static HTML files and mod_rewrite. Any advice on key_buffer and other values? –  danikaze Oct 19 '12 at 15:28
    
Both of the MySQL buffer settings I mentioned are based upon your data. The tuning-primer script will provide a report of your current values along with current usage. Naturally you don't have a lot of RAM to play with since Apache and PHP is taking up most of that. But if you can get the buffers to fully contain the indexes or at least 75% that will get you the best benefit. –  KayakJim Oct 19 '12 at 17:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.