VPS hosting is very slow. What's the bottleneck?
Solution 1
Make certain you are not regularly accessing swap space for anything - disk I/O is a very common bottleneck, particularly on Xen VPS' with relatively small RAM allocations (assuming you're at Slicehost, given your mention of using a "slice").
While having swap space seems like a plus (particularly because your VPS doesn't sputter and die when you try to run multiple memory-hungry applications like Apache w/dynamic PHP content and MySQL) it will quickly lead to substandard performance, particularly if you're on a VPS host node full of others doing the same thing.
Edit: I would highly recommend the LowEndBox Wiki (LowEndBox focuses upon virtual environments with memory allocations in the same neighborhood as your own) for optimization tips to get Apache and MySQL running smoothly within your virtual environment.
Solution 2
It's almost definitely not an Apache configuration issue, but you need to profile your application to find out where its time is being spent instead of blindly guessing at what the problem is. Xdebug is a popular tool for PHP profiling, and turning on the MySQL slow query log may help if MySQL is running inside your VPS.
Part of the problem with VPS environments is that since your VM doesn't really know what it's getting in terms of resources, it's practically impossible to determine if your server hardware is heavily oversubscribed. That makes things trickier.
Solution 3
First try the standard mpm settings:
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 150
MaxRequestsPerChild 0
</IfModule>
Maybe you should also have a look at this: http://articles.slicehost.com/2010/5/20/configuring-the-apache-mpm-on-debian You should also reduce the KeepAlive settings.
What about the RAM? Are you sure you have enough and the server is not swapping? (free -m)
You should also check your database, it's relative easy with the Tuning Primer script: http://www.day32.com/MySQL/
Btw. on a Server with just 256MB RAM i would advise you to use a other Webserver like Lighttpd or Nginx (with PHP-FPM).
Related videos on Youtube
aneuryzm
Updated on September 17, 2022Comments
-
aneuryzm over 1 year
I've setup a new VPS hosting, to run a Drupal website but it is extremely slow.
It is Ubuntu 10, Apache, php5.2
I've enabled Multi-Processing Module (MPM) module and configured it as follows:
StartServers 4 MinSpareServers 2 MaxSpareServers 10 ServerLimit 20 MaxClients 20 MaxRequestsPerChild 200
But it is still too slow... it is a VPS slice: RAM 256MB BW 150GB
what could be the reason ? thanks
Update (Swaps)
total used free shared buffers cached Mem: 245 220 24 0 1 26 -/+ buffers/cache: 192 52 Swap: 511 110 401
-
SiXoS over 13 yearsStart controlling database layer, and make sure you run a php byte code cacher like xcache
-
aneuryzm over 13 yearsI've installed mysql (it is local). Very simple installation as I always did before on other VPS.
-
aneuryzm over 13 yearsuhm ok thanks. But the point is that I've just setup the VPS, installed everything.. so there is not a lot to investigate. What could be the reason of php running slow.. or maybe Drupal running slow on a server ?
-
aneuryzm over 13 years@danlefree How do I check if the swap memory is used ?
-
aneuryzm over 13 yearsI've changed the values, but it is still the same. The server is fast if I visit a html page. It is a php/mysql problem I guess
-
aneuryzm over 13 yearsI've run the script you suggested but this is what I get - INITIAL LOGIN ATTEMPT FAILED -
-
zaub3r3r over 13 yearsYou have to set your login variables first in ~/.my.cnf
-
jgoldschrafe over 13 yearsCode isn't magic, it does things. The entire point is to figure out where it's running slow so you can figure out why it's running slow. As you said, you have absolutely nothing else to go on.
-
danlefree over 13 years@Patrick - Run
free -m
-
aneuryzm over 13 years@danlefree I've updated my question with the results. How should I interpret the numbers ? thanks
-
danlefree over 13 years@Patrick - It appears as though swap space is being allocated, though it may be held without being used. Run
vmstat -a 1
and watch thesi
andso
values while you request a page on your site to see how heavily swap is being relied upon (si
andso
will remain at0
if your server is not actively using swap). -
aneuryzm over 13 years@danlefree So, they are usually 0, but when I visit a page they both change (i.e. 0 0, 312 0, 324 1516, 36 6768, 0 0). So I guess the server is using swap.
-
danlefree over 13 years@Patrick - Yes, I would say that your server is relying upon swap to serve pages. Given that, your bottleneck is most likely disk I/O for all of those swap operations. Disk I/O on a shared server is an onerous bottleneck - do everything you can to avoid it.
-
aneuryzm over 13 years@danlefree uhm, What do you mean with "disk I/O". Are you talking low level, about number accesses to memory disk ? Or is it something else on VPS ?
-
aneuryzm over 13 yearsAnyway, I'm running exactly the same Drupal application on another VPS with the same RAM (256M) and it is not slow... (and I have more than 1 website there)
-
danlefree over 13 years@Patrick - By "disk I/O" I'm referring to low-level random access reading and writing (which involves a great deal of seek time per operation). Disk contention is a well-documented problem for low-end virtual private servers; swap space makes it worse. Related reading: etbe.coker.com.au/2008/08/27/…
-
aneuryzm over 13 years@danlefree I've just checked the swap on the other VPS hosting and the values are much lower (max 300).. I guess something in the configuration is different because the RAM is the same.
-
zaub3r3r over 13 yearsAs you can see your Server is swapping, try to disable Apache modules which you don't need. However i think that 256MB RAM are not enough to run a well performing LAMP-setup. Databases need cache and Apache also isn't a saveaholic. You should think about switching to Lighttpd, it's easy to setup and works well with less RAM. You don't need to worry about the rewrite-stuff, there are enough examples on the internet. I can't tell you why the same setup works on a other VPS, maybe different virtualisation or other hardware (faster harddrives ;) )
-
danlefree over 13 years@Patrick - Anything that keeps your server from fighting other domU's for swap space will help :)
-
aneuryzm over 13 years@danlefree The difficulty is to find out how to not swap.
-
danlefree over 13 years@Patrick - Take a look over the articles under "Software Optimization Guide" at the LowEndBox Wiki for starters.
-
aneuryzm over 13 years@danlefree yeah thanks, I saw it before, but the link seems to not exist lowendbox.com/wiki/setup-base-debian-ubuntu-vps
-
danlefree over 13 years@Patrick - That guide can be found here: lowendbox.com/blog/… (though it involves using a different webserver)