2016-04-25

Many people think upgrading the hardware is the best way to speed up a server. It seems intuitive that more memory, and more CPU can deliver better performance. But, hardware upgrades can deliver only a temporary fix, if the services are un-optimized.

[ Are you facing high load right now? Click here to know how to troubleshoot it. ]

In any server, the volume of traffic and the density of data changes over time. So, it is important to modify the server settings to optimally handle the changed traffic conditions.

In web hosting servers, the traffic heavy lifting is done by Web and Database servers. Today, we’ll take a look at how to optimize Apache web servers and MySQL database servers in cPanel and Plesk Linux web hosting servers.

[ If your servers do not use web or database services, here’s a guide on how performance tuning can be done on any server. ]

Optimizing Apache

The Apache’s configuration file is located at “/usr/local/apache/conf/httpd.conf” in a cPanel server and at “/etc/httpd/conf/httpd.conf” in a Plesk server. The initial step is to measure the current performance of the web server. You can use ab to benchmark the server. If you get “command not found” error while running ab, you can use the absolute path of the ab binary ie /usr/local/apache/bin/ab in a cPanel server. If you find it too much complicating, please use any online tools to measure the performance. The next step is to change the directives in the configuration file. Please note that you will have to restart Apache (/etc/init.d/httpd restart)for the changes to be in effect. The common directives that you can alter are:

Timeout

This directive “Timeout” is used to define the amount of time Apache will wait for a GET, POST, PUT request and ACKs on transmissions before automatically disconnect when idle time exceeds this value. The ideal value will be 120 in heavily loaded servers. It is recommended to set this value lower if your clients have low latencies. Some time, setting this directive to a low value may pause problem, this highly depend on your network and server setup. The best is to experiment with different values to find the one that fit your need.

KeepAlive

This directive “KeepAlive” if set to “On”, enables persistent connections on the web server. For better performance, it’s recommended to set this option to “On” and allow more than one request per connection.

MaxKeepAliveRequests

This directive is used to define the number of requests allowed per connection when the KeepAlive option above is set to “On”. When the value of this option is set to “0” then unlimited requests are allowed on the server. For server performance, it’s recommended to allow unlimited requests.

KeepAliveTimeout

This directive is used to define how much time, in seconds, Apache will wait for a subsequent request before closing the connection. Once a request has been received, the timeout value specified by the “Timeout” directive applies. The value of “10” seconds is a good average for server performance. This value should be kept low as the socket will be idle for extended periods otherwise.

MaxClients

This directive is used to define the limit on the number of child processes that will be created to serve requests. The default means that up to 512 HTTP requests can be handled concurrently. This is an important tuning parameter regarding the performance of the Apache web server. For high load operation, a value of “512” is recommended. For standard use, you can set the value to “256”.

MinSpareServers

This directive is used to define the minimum number of idle child server processes that should be created. An idle process is one which is not handling a request. If there are fewer than “MinSpareServers” idle, then the parent process creates new children at a maximum rate of 1 per second. The idle value is 10 MaxSpareServer: This directive is used to define the maximum number of idle child server processes that should be created. If there are more than “MaxSpareServers” idle child processes, then the parent process will kill off the excess processes and these extra processes will be terminated.The idle value is 15.

MaxRequestsPerChild

This option “MaxRequestsPerChild” is used to define the number of requests that an individual child server process will handle. Set this directive to “0” to get the maximum performance and scalability for the server.

HostnameLookups

This directive if set to “Off”, specifies to disable DNS lookups. It’s recommended to set this option to “Off” in order to avoid latency to every request, to save the network traffic time, and to improve the performance of your Apache web server.

[ Click here for an in-depth article on Apache performance tuning. ]

Optimizing MySQL

Once you have finished optimising Apache, you can proceed with the MySQL optimisation. As in the case of Apache, you will have to modify the MySQL configuration file. This file is located at “/etc/my.cnf” in cPanel and Plesk servers. You will have to reboot the MySQL server (/etc/init.d/mysqld restart) after making any changes to the configuration file.

A lot of MySQL tuning scripts are available today. You can use one of those scripts here . It is a perl script and you can run it using the command “perl mysqltuner.pl”. This will list the changes that you will have to make to the configuration file.

# wget http://mysqltuner.pl/mysqltuner.pl

# perl mysqltuner.pl

>> MySQLTuner 1.2.0 ­ Major Hayden <major@mhtx.net>

>> Bug reports, feature requests, and downloads at http://mysqltuner.com/

>> Run with ‘­­help’ for additional options and output filtering

The output of the script will be like:

Variables to adjust:

query_cache_size (>= 8M)

join_buffer_size (> 128.0K, or always use indexes with joins)

thread_cache_size (start at 4)

table_cache (> 64)

innodb_buffer_pool_size (>= 33M)

So you need to set the query_cache_size to 8MB or more. You can add the directive “query_cache_size=8M” in the MySQL configuration file to accomplish this. Similarly make changes to other directives, restart MySQL service and run the tuning script again.

[ Click here for a comprehensive guide on MySQL Performance tuning. ]

Optimising a server is not just confined to tweaking Apache and MySQL. You can tweak other services, switch to alternate webservers like Litespeed , schedule tasks with high resource usage like backups to off peak hours etc to improve the performance.

The above is a very rough outline on increasing the server speed , if you have any questions, we would be happy to talk to you! <img src="https://s.w.org/images/core/emoji/72x72/1f642.png" alt="

Show more