2

I just purchased my first VPS with 2GB of RAM. I had installed Apache + mySQL and 1 mainly static site and 2 wordpress site (for testing). At first, my memory peak at 1GB, which indicates that it needs further configuration.

Here is the result for running ps -ylC httpd --sort:rss
S   UID   PID  PPID  C PRI  NI   RSS    SZ WCHAN  TTY          TIME CMD
S     0 20729     1  0  80   0 10032 69902 poll_s ?        00:00:00 httpd
S    48 20770 20729  0  80   0 22768 73372 inet_c ?        00:00:00 httpd
S    48 20735 20729  0  80   0 24020 73897 inet_c ?        00:00:00 httpd
S    48 20740 20729  0  80   0 26524 74302 inet_c ?        00:00:00 httpd
S    48 20733 20729  0  80   0 27792 74831 inet_c ?        00:00:00 httpd

Here it the result using the command top

top - 15:42:01 up 18 days, 15:45,  1 user,  load average: 0.00, 0.00, 0.00
Tasks:  26 total,   1 running,  24 sleeping,   0 stopped,   1 zombie
Cpu(s):  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   2097152k total,   837604k used,  1259548k free,        0k buffers
Swap:  4194304k total,    15836k used,  4178468k free,   679184k cached
    1 root      20   0 19208  416  292 S  0.0  0.0   0:00.01 init
    2 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthreadd/179
    3 root      20   0     0    0    0 S  0.0  0.0   0:00.00 khelper/179
  491 root      20   0 80300  776  468 S  0.0  0.0   0:18.75 sendmail
  540 smmsp     20   0 76024  388  260 S  0.0  0.0   0:00.08 sendmail
  556 root      20   0  114m  368  284 S  0.0  0.0   0:02.47 crond
  726 root      16  -4 10660    8    4 S  0.0  0.0   0:00.00 udevd
  876 root      20   0 64272    8    4 S  0.0  0.0   0:00.00 saslauthd
  877 root      20   0 64272    8    4 S  0.0  0.0   0:00.00 saslauthd
  908 root      20   0  181m  864  416 S  0.0  0.0   0:00.04 rsyslogd
  928 root      20   0 22092    8    4 S  0.0  0.0   0:00.00 xinetd
 2100 root      20   0  105m 1180 1176 S  0.0  0.1   0:00.00 mysqld_safe
 2189 mysql     20   0  679m  19m 3888 S  0.0  0.9   0:41.22 mysqld
18759 root      20   0 94084 4772 3420 S  0.0  0.2   0:01.03 sshd
18761 root      20   0  105m 1952 1488 S  0.0  0.1   0:00.16 bash
20729 root      20   0  273m 9.8m 5124 S  0.0  0.5   0:00.04 httpd
20733 apache    20   0  292m  27m 4804 S  0.0  1.3   0:00.54 httpd

Here are the changes I made in httpd.conf

# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
#
KeepAlive On

#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 15

#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 5

Here is my prefork-MPM setting

# 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       2
MinSpareServers    3
MaxSpareServers    3
ServerLimit      35
MaxClients       35

I initially wanted to only have MongoDB in here. But I am planning on moving my WP installs from the shared hosting as well. All in all, I will have 2-5 wp site, 1 CodeIgniter Web app (No DB), 2 future Web App on fuelphp running MongoDB.

I like to keep the ram at max of 1.2GB if possible. Any suggestions for further tuning in apache side? I will see if I can reduce mysql footprint.

3 Answers 3

2

"How do I make my website go faster" is really far too complex a question to answer on this forum. However a few things of note:

  • yes the memory usage is very high, even for Wordpress
  • who cares? Unless you know that it's affecting performance then why bother worrying about it?
  • setting minSpareServers to the same value as maxSpareServers is not a good way to cope with changing demand profiles - Apache limits the rate at which new servers are started, I'd recommend changing maxSpareServers to 5
  • KeepAliveTimeout 5 - you changed this? This is still the default usually - and the default is much too high unless you know you're doing a LOT of Ajax / COMET stuff on mobile connections - recommend 2
  • Consider adding a reverse proxy such as nginx or varnish
  • Use ESI or W3 total cache plugins for your Wordpress install (ESI requires a ESI capable reverse proxy such as Varnish or ATS)
  • you've given no details of how MySQL is configured. If you're using innodb then the buffer pool should be sized to use up a significant chunk of memory (i.e. you should be aiming to REDUCE the amount of free memory on the system). If it's MyISAM then you need to keep lots of free memory available for VFS
  • You should START any memory tuning exercise by stripping out the stuff in Apache you don't need
  • You don't say how PHP is configured / invoked. Ideally it should be mod_php and an opcode cache
  • I wouldn't recommend switching to a different webserver unless you've got a lot more traffic than 35 concurrent connections
1

I just switched to Nginx after making some tests. Performance is much better now (Amazon EC2 micro instance with 613MB + running multiples layers on Java).

I you want to keep Apache, I would recommend to invest in one of those good books on performance, this one for example.

3
  • sadly the book is not available in my country.
    – Mr A
    Jan 9, 2013 at 8:40
  • Can you get it through O'Reilly Safari (online)? There are plenty of other titles worth a look. Jan 9, 2013 at 8:44
  • You're seeing this kind of profile after switching to nginx - but I very much doubt if you're running PHP+Wordpress. Tuning is not a one-size-fits-all solution.
    – symcbean
    Jan 9, 2013 at 10:45
0

1st Raise up MaxKeepAliveRequests. Low number of MaxKeepAliveRequests cause apache2 child to restart each time MaxKeepAliveRequests reached.

2nd Disable unused apache modules, like a ldap auth (if u don't need it)

2
  • 1
    For 2. Should I comment the module in the httpd.conf? Will that be counted as disabled?
    – Mr A
    Jan 9, 2013 at 8:28
  • 1
    Yep, just insert comment symbol infront to line, like # the line content
    – dr-evil
    Jan 9, 2013 at 9:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .