hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Managed Hosting and Services : How could I optimize my server CPU load?
Reply

Forum Jump

How could I optimize my server CPU load?

Reply Post New Thread In Managed Hosting and Services Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old
Newbie
 
Join Date: Jun 2009
Posts: 18
Question

How could I optimize my server CPU load?


Dear WHT Experts,

I own a dedicated server and I noticed high CPU load when I have around 1000 - 1200 visitors online at the same time. Could I improve the server load via settings or should I look into the website's code?

I have attached the TOP of my server, currently being in peak time. Also, please find below the server specs:

Quote:
Dell PowerEdge™R200
Intel®Dual Core Xeon®E3110 3,00 GHz
4 GB RAM
2 x 250 GB SATA HDD
Hardware RAID1
Remote Management Karte
Traffic-Flatrate
Backup M 2.0 & Monitoring M 2.0 inkl.
Standard Support inklusive
Please let me know if I could help you with some other details.

Thank you in advance for your help!
Attached Thumbnails
Clipboard01.jpg  


Last edited by CiZsolt; 02-22-2012 at 05:19 AM.


Sponsored Links
  #2  
Old
Web Hosting Master
 
Join Date: May 2005
Posts: 1,109
CPU isn't your only concern, you seem to be reaching the max for both ram and disk (for a good speed) as well.

You can increase the performance of your php applications by installing things like xcache, apc, etc.
You can make your scripts more efficient by making uses of caches
You can decrease the need for apache to work by installing something like nginx/varnish/lighttpd/litespeed as reverse proxy to apache to serve static files or handle it in replacement of apache.

  #3  
Old
Newbie
 
Join Date: Jun 2009
Posts: 18
Dear Grumps,

Thank you for your answer! I use caching via smarty tpl cache, adodbe cache for database queries, but I will also check the techniques you mentioned.

Do you think that ram and maybe disk space upgrade could be a solution to free up the resources?

Sponsored Links
  #4  
Old
Web Hosting Master
 
Join Date: Mar 2005
Location: Ten1/0/2
Posts: 2,439
There sure are a lot of apache processes there - using a lot of your resources.

What about putting Nginx in front of apache as a reverse proxy and to serve the static content.

__________________
CPanel Shared and Reseller Hosting, OpenVZ VPS Hosting. West Coast (LA) Servers and Nodes
Running Linux since 1.0.8 Kernel!
Providing Internet Services since 1995 and Hosting Since 2004


  #5  
Old
Newbie
 
Join Date: Jun 2009
Posts: 18
Hi RRHW,

Yes, we have always a lot of apache processes, and sometimes mysql is also on top (with 15-20%).

  #6  
Old
Web Hosting Master
 
Join Date: Nov 2009
Location: /etc/my.cnf
Posts: 9,448
Quote:
Originally Posted by CiZsolt View Post
Do you think that ram and maybe disk space upgrade could be a solution to free up the resources?
I think that a CPU upgrade and some optimization is needed more than anything.

The E3110 is some 4 years old its only a dual core and doesnt have hyper threading either...

__________________
LeapHost High Performance Wordpress & Magento Hosting Powered By Litespeed.
Fast Dedicated Servers | Uptime Cloud Monitoring | Proactive Server Management.
Server Setups | Stable Migrations | Security/Hardening | cPanel DNS Cluster Setups.
24/7 Ticket + Phone + Live Chat Support | Fancy An Offer > | Visit Our Special Offers


  #7  
Old
Junior Guru Wannabe
 
Join Date: Feb 2012
Location: WHT
Posts: 80
do u have linux or windows on it ?

  #8  
Old
Newbie
 
Join Date: Jun 2009
Posts: 18
I have a Linux dedicated server but I'm thinking about switching to the following configuration:

Quote:
CPU: 1 × AMD 8-Core
RAM: 32 GB
HDD: 4 × 1.000 GB
RAID: RAID10
I agree that the software part of the website could be optimized much more better, but I hope upgrading the hardware would do it until we manage to update/rewrite parts of the site too.

In your opinion, is the config mentioned above good?

  #9  
Old
Disabled
 
Join Date: Nov 2011
Location: Nasik, MH,INDIA
Posts: 850
Apache's RAM Usage
First and most obvious, Apache is hungry for RAM. This minor issue becomes a major when you realize that after each process has done its job, the bloated process sits and spoon-feed data to the client, instead of moving on to bigger and better things.This is further compounded by a bit of essential info that should really be
more common knowledge:
If you serve 100% static files with Apache, each httpd process will use around 2-3
megs of RAM.
If you serve 99% static files & 1% dynamic files with Apache, each httpd process will use from 3-20 megs of RAM depending on your MOST complex dynamic page.

  #10  
Old
Newbie
 
Join Date: Jun 2009
Posts: 18
Dear dareORdie, thank you for these useful details! I serve both types of files, the static ones being cached versions of the requested content.

  #11  
Old
Disabled
 
Join Date: Nov 2011
Location: Nasik, MH,INDIA
Posts: 850
Feels good, thanks
I think the following piece of info can even guide you the best way..

Unless you have very few dynamic pages and major traffic fluctuation, most of your httpd processes will take up an amount of RAM equal to the largest dynamic script on your system. A smart web server would deal with this automatically. As it is, you have a few options to manually improve RAM usage.

Reduce wasted processes by tweaking KeepAlive
KeepAliveTimeout is the amount of time a process sits around doing nothing but taking up space. Those seconds add up in a HUGE way. But using KeepAlive can increase speed for both you and the client - disable KeepAlive and the serving of static files like images can be a lot slower. I think it's best to have KeepAlive on, and KeepAliveTimeout very low (like 1-2 seconds).

Limit total processes with MaxClients
If you use Apache to serve dynamic content, your simultaneous connections are severely limited. Exceed a certain number, and your system begins cannibalistic swapping, getting slower and slower until it dies. IMHO, a web server should automatically take steps to prevent this, but instead they seem to assume you have unlimited resources. Use trial & error to figure out how many Apache processes your server can handle, and set this value in MaxClients. Note: the Apache docs on this are misleading - if this limit is reached, clients are not "locked out", they are simply queued, and their access slows. Based on the value of MaxClients, you can estimate the values you need for StartServers, MinSpareServers, & MaxSpareServers.

Force processes to reset with MaxRequestsPerChild
Forcing your processes to die after a while makes them start over with low RAM usage, and this can reduce total memory usage in many situations. The less dynamic content you have, the more useful this will be. This is a game of catch-up, with your dynamic files constantly increasing total RAM usage,and restarting processes constantly reducing it. Experiment with MaxRequestsPerChild - even values as low as 20 may work well. But don't set it too low, because creating new processes does have overhead. You can figure out the best settings under load by examining "ps axu --sort:rss". A word of warning, using this is a bit like using heroin. The results can be impressive, but are NOT consistent - if the only way you can keep your server running is by tweaking this, you will eventually run into trouble. That being said, by tweaking MaxRequestsPerChild you may be able to increase MaxClients as much as 50%.

Apache Further Tweaking
For mixed purpose sites (say image galleries, download sites, etc.), you can often improve performance by running two different apache daemons on the same server. For example, we recently compiled apache to just serve up images (gifs,jpegs,png etc). This way for a site that has thousands of stock photos. We put both the main apache and the image apache on the same server and noticed a drop in load and ram usage. Consider a page had about 20-50 image calls -- the were all off-loaded to the stripped down apache, which could run 3x more servers with the same ram usage than the regular apache on the server.
Finally, think outside the box: replace or supplement Apache Use a 2nd server
You can use a tiny, lightning fast server to handle static documents & images, and pass any more complicated requests on to Apache on the same machine. This way Apache won't tie up its multi-megabyte processes serving simple streams of bytes. You can have Apache only get used, for
example, when a php script needs to be executed. Good options for this are:

TUX / "Red Hat Content Accelerator" - http://www.redhat.com/docs/manuals/tux/
kHTTPd - http://www.fenrus.demon.nl/
thttpd - http://www.acme.com/software/thttpd/

Try lingerd
Lingerd takes over the job of feeding bytes to the client after Apache has fetched the document, but requires kernel modification. Sounds pretty good, haven't tried it. lingerd -

http://www.iagora.com/about/software/lingerd/

Use a proxy cache
A proxy cache can keep a duplicate copy of everything it gets from Apache, and serve the copy instead of bothering Apache with it. This has the benefit of also being able to cache dynamically generated pages, but it does add a bit of bloat.

Replace Apache completely
If you don't need all the features of Apache, simply replace it with something more scalable.

Currently, the best options appear to be servers that use a non-blocking I/O technology and connect to all clients with the same process. That's right - only ONE process. The best include:

thttpd - http://www.acme.com/software/thttpd/
Caudium - http://caudium.net/index.html
Roxen - http://www.roxen.com/products/webserver/
Zeus ($$) - http://www.zeus.co.uk

Solutions: PHP's CPU & RAM Usage
Compiling PHP scripts is usually more expensive than running them. So why not use a simple tool that keeps them precompiled? I highly recommend Turck MMCache. Alternatives include PHP Accelerator, APC, & Zend Accelerator. You will see a speed increase of 2x-10x, simple as that. I have no stats on the RAM improvement at this time.

Solutions: Optimize Database Queries
This is covered in detail everywhere, so just keep in mind a few important notes: One bad query statement running often can bring your site to its knees. Two or three bad query statements don't perform much different than one. In other words, if you optimize one query you may not see any server-wide speed improvement. If you find & optimize ALL your bad queries you may suddenly see a 5x server speed improvement. The log-slow-queries feature of MySQL can be very helpful.

How to log slow queries:

# vi /etc/rc.d/init.d/mysqld

Find this line:
SAFE_MYSQLD_OPTIONS="--defaults-file=/etc/my.cnf"


change it to:
SAFE_MYSQLD_OPTIONS="--defaults-file=/etc/my.cnf --log-slow-queries=/var/log/slow-queries.log"

As you can see, we added the option of logging all slow queries to /var/log/slow-queries.log
Close and save mysqld. Shift + Z + Z

touch /var/log/slow-queries.log
chmod 644 /var/log/slow-queries.log

restart mysql
service myslqd restart
mysqld will log all slow queries to this file.

References
These sites contain additional, more well known methods for optimization.

Tuning Apache and PHP for Speed on Unix - http://php.weblogs.com/tuning_apache_unix
Getting maximum performance from MySQL - http://www.f3n.de/doku/mysql/manual_10.html
System Tuning Info for Linux Servers - http://people.redhat.com/alikins/system_tuning.html
mod_perl Performance Tuning (applies outside perl) -

http://perl.apache.org/docs/1.0/guide/performance.html

Once again, if this has any errors or important omissions, you are most welcome to share.

  #12  
Old
Oh, I'm a Gummy Bear,
 
Join Date: May 2011
Location: New York, USA
Posts: 3,584
Drop apache and replace with litespeed or nginx, optinize sql server, if you got extra cash, setup a load balancer.

  #13  
Old
Newbie
 
Join Date: Feb 2012
Location: Poland
Posts: 22
Quote:
Originally Posted by SeriesN View Post
Drop apache and replace with litespeed or nginx, optinize sql server, if you got extra cash, setup a load balancer.
Yes its good advice

Reply

Similar Threads
Thread Thread Starter Forum Replies Last Post
Optimize Apache + Mysql High load server andre33 Hosting Security and Technology 5 01-19-2012 02:30 PM
Optimize my high load DEDI server andre33 Hosting Security and Technology 11 04-24-2011 01:45 AM
Optimize my hight load server andre33 Hosting Security and Technology 2 04-15-2011 07:45 AM
How do I optimize my server with High load. kunimii Hosting Security and Technology 7 07-18-2006 03:08 PM
Urgent, high server load. Optimize Apache HD Fanatic Hosting Security and Technology 10 12-28-2005 03:29 PM

Related posts from TheWhir.com
Title Type Date Posted
Rackspace Launches Automatic Cloud Scaling Capabilities Web Hosting News 2013-11-21 12:07:13
Linode Updates Cloud-Based Load Balancer Service with SSL Support Web Hosting News 2013-11-08 11:50:09
LeaseWeb Adds Load Balancing Service to Public Cloud Web Hosting News 2013-08-07 10:35:22
GoGrid Launches Dynamic Load Balancer Service Built for Cloud Web Hosting News 2013-01-29 10:07:53
Nginx Web Server Adds Device Detection at Server Layer with dotMobi DeviceAtlas Module Web Hosting News 2013-01-09 11:33:22


Tags
cpu load

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
WHT Host Brief Email:

We respect your privacy. We will never sell, rent, or give away your address to any outside party, ever.

Advertisement:
Web Hosting News:
WHT Membership
WHT Membership



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?