This ain't no ordinary Affiliate Marketing Blog - Grab the Feed

VPS Optimization Guide

05. Jan 2009 | 12 Comments

When you get to the level where you start needing VPS’ (Virtual Private Servers) it’s important to understand how they work & how you can get the most out of them. Poorly set up servers can cause you all sorts of problems like Downtime, Slow MYSQL or not withstanding the force of something like Digg.

This article will cover everything you need to do to ensure that your VPS is performing as fast as possible, which mostly focuses on optimizing your memory usage. Please ensure you make backups of your existing my.cnf & httpd.conf we will not be held responsible for any problems.

What you will need to action this guide:

  1. Your server specs (most importantly Guaranteed RAM & Burst RAM)
  2. Access to your Web Host Support for installation of
  3. Root access to your VPS via SSH
  4. FTP Access to your server
  5. A brief knowledge of an editior (i.e. VI) if not I’ll provide the commands you need to know
  6. How to restart mysql & apache in your server operating environment
  7. Access to WHM


Viewing your PHPinfo

Create a file called phpinfo.php & include the follow in it:

  1. <?php phpinfo();
  2. ?>

Navigate to that file on your server i.e. http://www.yourserver.com/phpinfo.php, you should see something like this:

PHPInfo

What you need to ask your host to do:

  1. Ensure that you have the latest PHP version (currently 5.28)
  2. Make sure that PHP is compiled with the latest version of Zend Optimizer, Eaccelerator & Ioncube Accelerator.
  3. Ensure that you have the latest apache version (currently 2.0.63)

Viewing your current resource usage

Log in via SSH, I normally use the Putty client for this.

Commands:

top: your current server load & resource usage.
ps aux: all your processes & which ones are using the most memory/cpu
free -m: allocated memory, usage & free memory

Top Command SSH

If you use the top command you can get an overview of the load on the server & memory usage. You can see in the screenshot above my VPS has a load of 0.02 during the last 1minute, 5 minutes & 10 minutes.

No-one really knows what the ideal “load average” should be but my general rule is that anything over below 1 is good & above 1 is average. Above 3 & you may start to notice performance issues.

With memory usage you should ideally have 100MB or so free (if not more), you really need that buffer for large traffic spikes. If you’re coming close to your allocated memory usage then any allocated burst ram will kick in. On my server I have no burst ram, just guaranteed which means I don’t have that buffer, but my system is more stable (as everyone on the VPS can make use of the burst ram).

Removing & Tweaking Unnecessary Services

There’s a number of services that you can remove or tweak to increase performance. To remove any of these services log into WHM & go to Service Configuration > Service Manager or Cpanel > Plugins in the left menu.

Clamd: This is a virus scanning service, it uses up a ton of memory do generally I’ll remove it.

Entropy Chat: Disable this.

Spamd: This uses a lot of processes & memory. You shouldn’t remove this, instead we can tweak it. Go to Cpanel > Plugins & install spamdconf, once done go to the bottom of WHM & click on Setup Spamd Startup Configuration. Change the maximum children to 1 or 2. This will stop spamd spawning too many child processes.

Cpanel Tweak Settings

In WHM under Server Configuration > Tweak Settings:

  1. Make sure default catch-all mail address is set to FAIL, this will use the least CPU time.
  2. Untick Mailman, this is a resource hog.
  3. Change the number of minutes between mail server queues to 180
  4. Uncheck Analog Stats, I also usually uncheck Webalizer.
  5. Make sure you tick delete each domains access logs after run, otherwise you’ll start using heaps of Disk Space.

Mysql Optimisation

You can edit your mysql configuration (/etc/my.cnf) by typing vi /etc/my.cnf

In order to add something in vi you need to hit insert, once completed hit esc then :wq to save & quit. If you want to save without quitting type :q!

There’s a few important variables that we’re going to tweak:

  1. max_connections
  2. wait_timeout
  3. thread_cache_size
  4. table_cache
  5. key_buffer_size
  6. query_cache_size
  7. tmp_table_size

Via ssh you can type ‘mysqladmin variables’ to see their current values & you can also see a refreshed processlist by using the command ‘mysqladmin –i10 processlist extended-status’.

The settings below should work well for a server with 512MB Guaranteed RAM (also leaving you enough free for traffic spikes), if you have burstable then you can probably look at increasing the number of max_connections to 400 & possibly the key_buffer to 64M:

  1. [mysqld]
  2. max_connections = 300
  3. key_buffer = 32M
  4. myisam_sort_buffer_size = 32M
  5. join_buffer_size = 1M
  6. read_buffer_size = 1M
  7. sort_buffer_size = 2M
  8. table_cache = 4000
  9. thread_cache_size = 286
  10. interactive_timeout = 25
  11. wait_timeout = 7000
  12. connect_timeout = 10
  13. max_allowed_packet = 16M
  14. max_connect_errors = 10
  15. query_cache_limit = 2M
  16. query_cache_size = 12M
  17. query_cache_type = 1
  18. tmp_table_size = 16M
  19. skip-innodb
  20. [mysqld_safe]
  21. open_files_limit = 8192
  22. [mysqldump]
  23. quick
  24. max_allowed_packet = 16M
  25. [myisamchk]
  26. key_buffer = 64M
  27. sort_buffer = 64M
  28. read_buffer = 16M
  29. write_buffer = 16M
  30. [mysqlhotcopy]
  31. interactive-timeout

Apache Optimisation

Apache settings are located in httpd.conf, you can use ‘locate httpd.conf’ or ‘whereis httpd.conf’ to find it.

Optimal settings for apache should look something like this, I like to keep the min & start servers slightly lower to stop too many child processes spawning & using memory:

  1. KeepAlive On
  2. MaxKeepAliveRequests 100
  3. KeepAliveTimeout 1
  4. MinSpareServers 5
  5. MaxSpareServers 10
  6. StartServers 5
  7. MaxClients 150
  8. MaxRequestsPerChild 1000

Restarting Mysql & Apache

Once you’re done you’ll want to restart mysql & apache. You can do this via the command line or via WHM.

Restart Mysql: /etc/init.d/mysql restart (if mysql doesn’t restart consider commenting out skip-innodb in my.cnf)
Restart Apache: /etc/init.d/httpd restart

These commands may vary depending on what your server is running.

Monitoring Changes

Use the ‘top’ command, ‘free - m’ & ‘ps aux’ to get an idea of how the server is responding. Pay attention to how much RAM you have left & also how much CPU Mysql & Apache is using. You may need to leave Mysql running for 24-48 hours to get a true picture here.

Thinking about upgrading to a VPS but not sure who to choose, let us help you with our VPS Web Hosting Reviews, tailored specifically for Affiliate Marketers.

  1. top - 19:56:30 up 27 days,  4:11,  1 user,  load average: 0.04, 0.07, 0.09
  2. Mem:    524288k total,   386432k used,   137856k free,        0k buffers
Enjoy this post? Get the RSS Feed

Or get updates by email:


Prev Article: 13 Smokin Tips to Increase Adwords CTR

Next Article: Advanced Forum Link Building


Not making any Money yet? Check out these posts too:

Random Post: Want to earn more? Read a Random Post!

http://www.earnersblog.com/wp-content/plugins/sociofluid/images/digg_48.png http://www.earnersblog.com/wp-content/plugins/sociofluid/images/stumbleupon_48.png http://www.earnersblog.com/wp-content/plugins/sociofluid/images/delicious_48.png http://www.earnersblog.com/wp-content/plugins/sociofluid/images/facebook_48.png http://www.earnersblog.com/wp-content/plugins/sociofluid/images/sphinn_48.png http://www.earnersblog.com/wp-content/plugins/sociofluid/images/twitter_48.png

12 Comments on "VPS Optimization Guide"

Andreas 23. Dec 2008, 3:17 am

Aren’t you using dedicated servers already?

Stuart 23. Dec 2008, 6:37 am

5 VPS at the moment. I prefer to spread out my sites rather than cluster them on 1-2 dedicated servers.

Garrett 06. Jan 2009, 2:29 am

Stuart,
Do you have any advice for when you REALLY need to make a transition to VPS hosting? Is it all about bandwidth? I’m currently using shared hosting (reseller plan) which allows me to host 30 domains for about $25/mo. I’m using all 30 slots right now, but only about 5 sites pull “ok” traffic.

I’m not exceeding my storage or bandwidth allotments….is that the major thing that should make me consider VPS? All of my sites are currently on the same IP, so I guess there is some risk there (but I’m not interlinking or doing any “dark arts” here). Will VPS give me ability for multiple IPs (I’m sure it comes with higher cost)?

Anyway, I’m just curious if you’ve got any guidelines for when you really need to start thinking about upgrading. I’m definitely making much more than $25/month in profit right now, but it’s nice to have a low fixed hosting fee….am I shooting myself in the foot by cheaping out here??

Thanks.
-G

Stuart 06. Jan 2009, 8:47 pm

Garrett, there’s a few reasons to look into a VPS.

Flexibility: You can do what you want, have as many IPs as you want, perform your own backups etc

Support: If the shit hits the fan you can get the support you need FAST, rather than within 24 hours on the “busy shared hosts”

Scalability: If your site takes off you know you can scale your resources easily.

But at the same time, if you’re not having any issues then you need to evaluate if you’re happy with your current provider. A VPS will run you about $30 - $60 a month but you’ll notice a considerable increase in performance.

Check out Knownhost or Wired Tree both very good.

Hope this helps.

Garrett 07. Jan 2009, 2:10 am

Thanks man.

Dan Carrigan 07. Jan 2009, 4:32 am

I know you mentioned Knownhost and Wired Tree, how do you feel about LunarPages? It’s supposed to be cheaper…
Thanks
Dan

Tjäna Pengar 11. Jan 2009, 10:42 am

To be honest i think shared hosting works fine until you feel the need for something more. If you max out the traffic or see your sites perform slowly maybe it could be worth considering. I have about 50 sites bringing in good money and traffic and they all on shared hosting. Not all at same shared hosting, but still I have no need for anything else. The few times i have had problems i called the support and it was resolved in 20 mins.

Madmouse Blog 13. Feb 2009, 1:51 pm

I usually run on a dedicated server, but I was forced back to a VM server temporally. My co-location provider just got to expensive for costs because of the cost of electricity here in the Minneapolis, area.
So, my administrator sent off a server to another co-location provided that is out of state. I ended up with two cores of a Xeon 2.6, 2GB or ram and 80GB hd space. Not sure if that is enough power, but I want to get the most out of it.

I have wp-super cache running, but there is some kind of issue with it and the platinum SEO plugin. When enabling category functions to no index or no follow, I end up with all kinds of rel link errors, so my site doesn’t validate. So, I went back to all in one SEO plugin with wp-super cache. Seems to be working, but will take some time to really tell how stable it is.

The information in your post will at least help me speed a couple of things up and I will be shooting this link off to my administrator.

CrumX 06. Mar 2009, 4:17 am

Thanks for this guide well I manage to lower down ram usage and finally starting to get rid SQL error 1 by one by following this guide.

I currently use Santrex as my VPS.. It cheap as its unmanaged yet the “unmanaged” terms really piss me off sometimes as when u ask via support ticket to sales dept they said everything is pre configured but in reality its not optimized. You will be given a VPS running in httpd at 1st before you know that after u change it to apache everything will goes worng. High RAM usage (I did send em support ticket asking about this and thier answer is *It’s normal*)

I manage to reduce from 250-MAX used to 140-200 used on RAM with 300 user online. The only problem now is SQL giving a few time out error. I manage to get rid of it by adding this on my.cnf as its not there by default.

[client]
por = 3306
socket = /var/lib/mysql/mysql.sock

Regarding the wait_timeout after set it to 7000 on mycnf when I check variables again It’s only show 10 well by default it something around 28800 so I was wondering if this is normal? But so far I didn’t get error “MySQL Server has gone” yet. I will update if I found the problem

Rob Bunger 27. Apr 2009, 10:36 am

Hi! I’m a completely newbie here, and this is my firwst post, but I’m considering my options with regards to hosting my DNN websites, and wanted some feedback on generic website hosting or my own dedicated server to host my sites.

I’ve narrowed my dedicated server hosts down to 2 finalists… ServeSouth (www.servesouth.com) and VPS Express (www.vpsexpress.com) if I go the dedicated route because I get FULL root access, no setup fees, low monthly costs, and great support. However, I DO have to manage everything myself.

On the other hand, there are the “GoDaddy’s” of the world, and there are literally THOUSANDS of them that just provide a place to park a site, and you just FTP your stuff to them and hope for the best. My concern is the complete lack of control and questionable security for the super-cheap hosts.

ServeSouth and VPS Express are both based here in Atlanta, and I have had the chance to tour their incredible data facilities, so I know that they are for real and not based in some loser’s garage or basement!

So, I welcome any input on the differences and Pros & Cons. Also, if I should look at other dedciated hosting providers, what kinds of things should I be looking for that ServeSouth and VPS Express don’t currently offer?

Thanks!

Ali B. 22. Jun 2009, 1:13 am

Quite an interesting and detailed post, Stuart. Thanks. One, very minor, typo though. ‘:w’ saves the file without quitting, while ‘:q!’ quits without saving.

Add a Comment





Supporters of the Cause

Earn extra cash with Netklix text ads. Start today!

Popular Articles


Recent Posts

Affiliate Tools

Guides / Example Sites