As the number of visitors to a website increases, so does the strain on the server. This can result in a very high load, especially if the available resources are tight and there is not enough CPU or RAM to serve all requests.

A high server load can significantly increase loading times or even make a website completely unresponsive, so it is very important to handle this issue proactively and spread the load before it becomes a real problem.

There are several methods to reduce server load, depending on the budget at your disposal, we will discuss them briefly starting with the cheapest options.

Optimize your server

If you can’t afford more resources, the only option is to optimize your website so that it runs best on the current server.

Start by making sure that you only run the applications that you actually need, since every unused service is just draining your CPU and memory. The same is true for plugins, such as the ones installed in WordPress.

Optimizing php is tricky and you’ll probably need help from a programmer, but there are still a few things you can try. If your website is compatible with caching solutions like opcache, memcache or redis, make sure these are activated, since they can make a huge difference.

Every new php version is faster than the previous one and uses fewer resources, so you can update php step by step as long as your site loads correctly. You can jump straight to the latest version if you use a modern CMS platform like WordPress.

Your database server should also use the newest version of MySQL or MariaDB for best performance and resource use. A diagnostic tool such as MySQLTuner can suggest some useful tweaks in your configuration files.

Another great tool is mytop, which allows you to inspect SQL queries as they run. Identify the slow ones that cause high server load and ask your programmer to investigate them.

Finally, an effective caching system can greatly decrease the load on your server and allow it to respond to more requests at the same time.

Even the caching of static files is very helpful but you can also cache dynamic pages as long as the settings are right.

There are many caching options available; every CMS has several internal options or plugins. You can also install Nginx for caching in front of Apache, or use other solutions like Redis or Varnish for this purpose.

Scale up

Adding more resources will definitely decrease load, if you can afford them.

This is more difficult on a physical dedicated server, you might be able to add more RAM or migrate to a larger machine but this requires downtime.

However, scaling up is easy on a VPS and every cloud or virtualization solution supports it, a simple server reboot is required. Try to increase the number of CPU cores or the amount of system memory; you can also migrate your disks to a faster storage solution like SSD, if such an upgrade is available.

Move to a multi-server architecture

Scaling up on a single server has its limits and spreading the load to multiple servers eventually becomes a more effective option.

You can split the resource pool into several virtual machines with specific roles, depending on the needs of your website.

Linux applications run better on dedicated machines, when they don’t share resources with other services. The most simple multi-server setup for a php + MySQL site uses two machines, one is used only as a database server while the other connects to it remotely and handles the web server and php processing.

If this setup is unable to handle the traffic, it is time to implement a more complex solution. Two or more web servers can share the load between them, in this scenario you will also need a machine that will act as a load balancer in front of them.

The load balancer can be configured with Nginx or HAProxy and its role is to distribute requests to the backend web server that can respond faster. The web servers must share the same document root, which can be achieved by exporting a NFS mount or creating a separate machine for this purpose.

This solution has many advantages: it is easily scalable by adding or removing web servers and also offers some redundancy, since the site stays online even if one of the web servers crashes.

If you have a generous budget, it is also possible to implement a fully redundant solution, with a backup load balancer (using VRRP) and two database machines in a master-master setup.

 

Optimizing server load is a difficult task and even some of the biggest websites can struggle when the traffic is very intense, for example during Black Friday.

The right configuration depends on the available resources and the specifics of your website; follow the basic steps described in this article to setup a solid initial platform.

Facebooktwittergoogle_plusredditpinterestlinkedinmail