Results 1 to 1 of 1

Thread: VPS Optimization Guide

  1. #1
    xCloudz is offline Junior Member
    Join Date
    Jan 2009
    Location
    Malaysia, MY
    Posts
    15

    Default VPS Optimization Guide

    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. 404 - Not Found, you should see something like this:
    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
    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 b




    Source: earnersblog
    Last edited by xCloudz; 07-05-2009 at 05:04 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •