Causes of High Server Load

Maybe its just your hosts system?

Following up on noddy, my (former) host took my website down claiming that it was putting their servers under too much load. To cut a long story short, the host discovered faulty hardware was their problem.

Just to add to what petesmc said, if you are doing about 1M page views per month, with 15-20 queries each time, that is 15-20 million queries, or about 5 - 7 queries per second on average.
while this is obviously less than MySQL is able to respond to it may be that your hosting (shared I assume) just considers 5 queries a second to be too many and too intensive for one site.

If you’ve already done all the caching you can, and there are no actual mistakes in the code that cause more work than necessary to be done I don’t really know what else you can do except get a dedicated server. I guess though certain PHP settings such as turning off register globals and magic quotes could give some performance boost if they are on now, but I imagine such tweaks would be marginal.

Something you should consider when looking at the causes of high server load on shared hosting systems are the following:

Do they use cpanel, webppliance, plesk or some other ‘generic’ hosting control panel. Many of these tend to run CGI scripts and PHP etc. in the most secure way possible, this means there is a large performance hit for every page visited (see cgiwrap, phpsuexec etc.).

You could suggest to your webhost to install PHP a php bytecode cache (ionCube PHPA, Zend Performance Suite, mmcache etc.), and enable query caching in MySQL (a 5 or 6mb cache should be ok). Although this will decrease the security of all PHP applications running (they’ll be required to run using mod_php or via fastcgi), the performance increase will be very noticable.

If you are on a virtual server, then the cause of the slowdown might not be your site!

are you hosting on hostony? I got my site wiped off by them for a similar reason. I am ok now with other hosts and was ok before also.

I would second the recommendation of copying the site setup to a testing machine and running some profiling tests.

This will help you determine 2 things…

  1. If it is actually your site causing the problems.

and, if so…

  1. What part of the code in particular is causing the problems.

Good luck and keep us posted.

Aye, I’ve moved server now, and the effect is still apparent. I am going to optimise each script individually, and try and bypass using an SDK for the log in.

Apparently, even my requests to image files are slightly more heavy on the CPU–I was shown a list of requests and there was a CPU column (using WHM HTTP control panel) where my requests were somewhat higher.

My mySQL queries are not less than 0.001 i actually meant 0.01s, most are near to 0.003 but a few are in the thirds of a second. I tried optimising one query by adding an index to the column but it made little difference.

Viflux: How is it possible to determine what part of the code is causing the load?

Viflux: How is it possible to determine what part of the code is causing the load?

One option you have is to profile your code, setup your site on a local machine (including database, try and make it as live as possible). Then use a professional PHP IDE (such as NuSphere PHPed, or Zend Studio) that can profile your code.

NuSphere PHPed gives you a nice call graph comparing how much time is spent in each function, which can clearly give you a good overview of which functions are hogging resources.

http://www.phpfreaks.com/articles/176/0.php - Tutorial using APD (Advanced PHP debugger - free) to profile code - non UI.

Another question no seems to have asked yet. Where is the load coming from. Do you have a shell account on the server… if so, can you run top? Is the load coming from PHP, Apache, MySQL? That information can help you to diagnose where the problem is. A buddy of mine had issues with Apache that was causing the server to spike. Only from one site though. Something to do with the size of the output buffer going to apache. After recompiling apache the problem went away… You might look into that.

So I guess that’s where a function like register_tick_function() can be very usefull…

This won’t make a major difference but be sure to move all your rewrite rules out of .htaccess files and ditch them entirely. Put all your rules in the httpd.conf file. It is more efficient :slight_smile:

RUnninbg xdebug on your code is good for profiling

That seems liek a very low percentage of Queries Per second to cause a high load. I’m currently serving over 1M pageviews per month with the following server load/MySQL stats on p4 *nix box with 1G RAM:

load average: 0.78, 0.67, 0.41

Opened Tables/second = 0.004 (/hour = 15.977)
Slow Queries/second = 0.000 (/hour = 0.732)
% of slow queries = 0.000%
Queries/second = 41.575 (/hour = 149668.634)

I would want to know what type of hardware is on your box. That is a decent amount of traffic but shouldn’t be near putting a strain on the server. I would run a top command from SSH when the server loads down to see what is draining the resourses.

have you setup indexesin mysql? a friend of mine was having the same issue and that’s what it turned out to be.

I think I may have solved my problem. I previously assigned a function for output buffering which manually gzencoded and reduced excess whitespace for all HTML files. I will update you with a definite answer to whether it has worked later.

Hey, mayble mysql-data-seek() function could help you. Replace dashes with underscores.

just had to ask…but you’re not running an ikonboard somewhere are you? :lol:

I know this site that has like 120 queries, yes one hundred and twenty!!! They get like 5K page views per month but yet require a dedicated server. Shows what too many innefective queries can do.

I would suggest using a caching system where the page is regenerated every X minutes. If you’re getting 1,000,000 page views per month this probably means multiple page views per second, so setting the cache to like 1 minute would reduce load big time, and still keep the page updated enough. My home page for example has probably like 20 or so queries, all simple selects with low limits but still enough to bog down a server if there happened to be tons of visitors, so I cache it every 15 minutes. It automaticly regenerates itself if someone goes on and that the cached copy is older then 15 minutes. output buffering is your friend, so is joins. :smiley:

Red Squirrel: That is not so easy when you have to work with user sessions also. I will try and figure out if there are other ways to do it.

The output buffering function removal seems to have improved quite a bit, but the load is still going quite high. I will try and cache more things on other pages other than the home page.