Linux – How to optimize the.cnf and httpd.conf for speed on a powerful dedicated server

apache-2.2centoslinuxMySQLoptimization

I have a dedicated server that has 12GB of RAM and Dual Nahalem Quad Core processors. My site usually only has about 50-100 users online at a time (though once I get the server optimized I plan on advertising and estimate the number to be closer to 250, which should still be very easily handled by this server). For some reason, even with these low numbers, the site seems to lag quite often with almost no server load.

I have been using mysqltuner.pl to try to get some things setup better in my.cnf. At this user level the site runs about 200 queries per second and is about 50/50 reads/writes.When it comes to Apache settings, I would have absolutely no idea what to change.

I am mainly just looking for general suggestions of things to update to better optimize performance of the server so that pages actually load quickly. It is worth noting that the pages loaded fairly quickly until a few days ago when the average online increased by 3-4x (though the server load hasn't really increased).

This is a CentOS 5.4 server if that matters.

Best Answer

The kind of numbers you are talking about are tiny, and as you observed load didn't change during that time period, so I don't expect this to be an issue of tuning apache or mysql directly.

In my experience of chasing issues like this down it's almost always ties into SQL. I would isolate what part of the page is consuming all of this time. Insert timer calls throughout the page in question and store the data somewhere you can review it (spit it to stderr and apache's error log if nothing else). Until you know the precise part of the code that is causing your slow down you will just be guessing.

Some possibilities:

  • A query into a table that has grown very large and is now slow (lacks index? needs pruning?)
  • A session table that is never pruned and has grown massive
  • A very subtle corruption (run through and optimize all your mysql databases to fix)
  • An ugly query that does heavy calculations every page load that could be optmized by saving the result in a cache.

I would also go back to basics and see if you can't find out what changed "a couple days ago". Was the page modified? Upgrades?

Another thing to check is I/O (iostat) to see if you may be I/O bound, though usually you will see symptoms in load for that.