Due to an excessive increase in load, the virtual server can begin to "suffocate" - it simply will not have time to process all incoming requests and perform the assigned tasks. As a consequence, there will be delays in the server, and the loading speed of the site pages will decrease to unacceptable values. In this article, we will talk about what causes can provoke this, how to conduct an analysis to assess the load on the VPS server, and what are the ways to solve the problem.
First of all, it is worth considering and eliminating the most obvious and natural reasons for the load on the VPS is consistently one hundred percent:
The natural growth of traffic from DDoS is quite easy to distinguish - in the case of a targeted attack, the number of visitors increases several times almost instantly. This is not the case with natural growth, because in this case, the graph of traffic growth will be smooth.
If the high load on the server is due to natural causes, the solution is one - to scale capacity. It is necessary to contact the hosting provider and negotiate to increase the hardware capacity of the server - CPU, RAM, etc.
The statistics section is built into almost all control panels, but sometimes this data is not enough for a more in-depth analysis of the server. The ideal tool in this regard is the *NIX utilities - to get detailed information about the server in real-time, you need to enter the top command into the console. Not all distributions contain this utility by default, so you may need to install it first. For Ubuntu the command will look like this:
$ sudo apt install top
You can run it with the same command
Now let's go over its main options, which may be useful to you when analyzing the server:
After starting the utility you will see detailed statistics on the CPU and RAM load, the number of running processes, as well as information on the amount of free and occupied physical memory on the server. You can use the above buttons to activate the necessary options for filtering and monitoring processes.
Apache is software that hosts web servers. It is a link between the user and the server - as soon as a person visits a website page and makes a request, Apache comes into play - it finds the data it is looking for and sends them back to the user. The same principle works in the opposite direction.
One possible scenario for using Apache is to collect and analyze statistics on the load on the processor and other server components. But the main advantage of the webserver is that its modules can detect incorrectly running scripts which may also cause a high load on the server. A developer or a system administrator, if they have the necessary experience, will be able to debug them. For tracing it is necessary to use xdebug or xhprof extensions.
The Apache web server is well suited for hosting large projects and is compatible with CentOS, Debian, FreeBSD and any other servers. Thanks to the modular structure of the software at any time you can load individual elements, extending the standard functionality as needed. There are over 500 modules available for Apache. Popular web applications are often provided as modules for Apache - for example, ISPmanager and VDSmanager control panels.
The only nuance is that a certain level of IT literacy is required to work competently with Apache. At least the basics of basic programming and web server administration will be required.
Advanced administrators can use logs - files that log all events on the server. Log files can belong to categories of applications, events, services, and system, and each of these categories can in theory be the cause of increased load on VPS server. Typically, on Linux-like systems, logs are located in the /var/log directory. Here is some information about those logs that may be useful for you to determine the causes of increased load on the server:
Manually examining the logs is a painful but rewarding task, because in theory, it allows you to identify the smallest errors in order to eliminate them in the future and optimize the VPS.
Let's consider one by one all the main and most common causes that can provoke an increased load on the server.
You can check if your limits are configured correctly by monitoring the values of MaxClients and MaxSpareServers. To see them, you need to enter the console command top, which we described in detail above.
You can calculate the optimal values with a simple formula:
MaxClients = M*0.8/H
Where M is the total amount of memory, and H is the amount of memory consumed by a single web process. The optimal values should not be higher than 10. You can use the appropriate Apache configuration file to limit this:
Setting values too low is also not worth it, otherwise, incoming and outgoing requests will not be able to run at a normal speed, or will be suspended at all. These files should be configured carefully while keeping in mind how many resources you have on your virtual server, and how to distribute them properly to optimize their performance.
To make it clearer, let's look at an example. Suppose we have a server with 16 GB of RAM. Two-thirds of the 16GB is 10.6GB. On average one process on a web server consumes about 40-60 MB of memory. We divide 10600 by 60 and get 176 Mb, round it down, and put in a value of 175. As a result, a block of a configuration file for Apache should look like this:
A little bit of explanation beforehand. The StartServers parameter specifies the number of child processes that are created when the server starts. MinSpareServers is the minimum number of unused child processes that are waiting for a potential request. MaxSpareServers is the same, only it is the maximum number of spare processes. The most important parameter here is MaxClients, this is the first one to pay attention to, because it defines the upper limit of simultaneously running processes.
Parameter MaxRequestsPerChild is worth mentioning separately: it sets the limit on the number of connections a child process can handle. It is very useful for memory leaks on the Apache server and its libraries. Usually specify 0, because other values can cause malfunction of the webserver.
A method that competitors or simply ill-wishers can use to spike the load on a particular server with one single goal - to bring it to failure and make the site inaccessible to users. Protecting yourself from DDoS can be done in different ways, but the simplest is to close all but three ports:
Simply put, you should make sure that only ports, protocols, or applications with which the administrator has provided access to the application or resources. You should also take care to implement three basic methods of DDoS protection: at the edge of the network, with a local cleaning center, and by redirecting traffic to the cloud.
A positive and quite natural reason - if your project is successfully growing and developing, the increase in visitors to the site will inevitably provoke an increase in server load, up to the appearance of performance problems. The solution is simple - to scale capacity, move to a more powerful VPS. If you have any questions, please contact HostZealot specialists and we will tell you everything you need to know in detail.
Sometimes high traffic can be caused by bots, which will not do you any good by increasing traffic but will consume a decent amount of resources. To protect VPS from them you can use robots.txt or .htaccess file.
A suboptimal distribution of resources between the scripts may well cause delays and slow down the server, as we mentioned earlier. You can use the xdebug or xhprof extensions to monitor and debug "crooked" scripts. You can also install nginx in conjunction with APC.
When there is not enough free space in the buffer to execute complex processes, the server will refer to the disk to place temporary files on it. To solve this problem you should increase the memory size allocated for temporary tables tmp_table_size and max_heap_table_size through the my.cnf settings file.
Try to set it to 32 MB and see how the Created_tmp_disk_tables variable behaves - the lower it is, the better.
In this case, the problem may be caused by problematic indexes or tables - you should check the logs and tables in phpMyAdmin.
If your server is infected with malware, it can start sending spam to hundreds of different addresses, all at the expense of your server capacity. Here's what you should do:
It could also be that your users send a large number of emails on purpose, so this is also worth checking.
Incorrectly configured backups can cause a load on the server at the most inopportune times. To avoid such mishaps, you can disable or reconfigure the feature so that data is backed up during hours when the load on the site is minimal.
The most unpredictable situation is when it is impossible to determine for sure what processes load the web server. This happens most often as a result of a hack, so you need to urgently take all measures to eliminate the threat and improve the security of the server:
You can also contact the hosting administrator to get more detailed advice and help with the solution to your situation.