I have a small Ubuntu server with 512MB of ram and several php/mysql websites (~20) running on it.It's been running for 2 years now without a single issue. But I think the moment for some optimization has just came.
The website that are hosted on this server are very low traffic, but I see some CPU issues now that they started to get more visits.
First thing I'm trying to do is identify the issues, so I've been playing around with several command line tools, like top htop apachetop, etc, and workbench for monitoring MySQl.With these tools is kind of difficult to know what i's going on exactly. For example, I created a PHP daemons that is running in the background, and every 10 seconds stores in the database the CPU usage.If the CPU is bigger than 60%, it stores the output of apachetop. This hasn't been specially useful since many of the records are OPTIONS * HTTP/1.0. Also, it looks like it's a list of the last requests, not the current request.
Seconds, when I try to monitor what's going on using htop, I always see ~15 records like:
6905 mysql 20 0 462M 110M 5220 S 0.0 21.6 5:29.79 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-external-locking --port=3306 --socket=/var/run/mysqld/mysqld.sock
and another ~15 like:
23382 www-data 20 0 259M 27384 4820 S 1.3 5.2 0:01.00 /usr/sbin/apache2 -k start
here's an screenshot:
I'm not sure if that amount of processes should be open all the time or this is something I can optimize. I can upgrade this server now, I just want to optimize it as much as possible before doing it.
Also, I turned on the log for slow queries, the only queries there are all queries that are executed when the server's CPU is over 90%. This just confirms that php/mysql I'm using (custom) is not very heavy. I can say that the website with more traffic has 300 unique visitors and 1200 page views a day. All other websites have much lower traffic.
1) I'm looking for suggestions of how to monitor this server efficiently.
2) I need suggestions for MySQl and PHP. For example, how much memory should I assigned to them or which options should I turn on/off.
here's a link to a screenshot of htop: http://www.flickr.com/photos/58586868@N02/5375745794/