How to solve VPS high load? Performance optimization method + complete guide to CPU memory expansion

Is your VPS overloaded and about to collapse?

Starting with the 4-core 16GB configuration, this article analyzes in detail how to choose the appropriate number of CPU cores and memory, and provides a comprehensive guide to optimizing VPS performance.

Whether it is database optimization, PHP application adjustment or hardware upgrade, we have specific suggestions to help you find the best solution to make your VPS run faster and more stable, and say goodbye to performance bottlenecks!

I hope these can help you, so that your VPS will no longer be as busy as a kebab stall!

The VPS is heavily loaded. How many CPU cores and memory should be upgraded to?

How to solve VPS high load? Performance optimization method + complete guide to CPU memory expansion

Assume that the VPS configuration CPU is 4 cores + 16GB memory, check top The load situation is serious. How many cores and memory should be used for the VPS?

top - 02:34:42 up 1:55, 3 users, load average: 54.22, 34.14, 32.00
Tasks: 179 total, 72 running, 107 sleeping, 0 stopped, 0 zombie
%Cpu(s): 70.7 us, 27.4 sy, 0.0 ni, 1.9 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 16777216 total, 2584976 free, 13411120 used, 781120 buff/cache
KiB Swap: 0 total, 0 free, 0 used. 3282716 avail Mem

(此处省略……)

from what you provide top Judging from the command output, the load of your VPS is quite high, with the average load reaching 54.22 (last 1 minute), 34.14 (last 5 minutes), and 32.00 (last 15 minutes).

This indicates that your system is experiencing high usage. Your VPS has a 4-core CPU and 16GB RAM, but the used memory is 13,411,120KiB, of which only 781,120KiB is used as buffer.

according to top From the command output, you can see that there are several resource-intensive processes:

  • mariadbd (MariaDB database service):Takes up a lot of CPU resources (143.1%).
  • memcached:Occupies a certain amount of CPU (7.7%).
  • Multiple php-cgi processes:Each takes up certain CPU and memory resources.

How to solve VPS high load?

Solutions to high load may include:

  1. Optimize the database:If mariadbd takes up a lot of CPU, you may need to optimize database queries or consider increasing the resources of the database server.
  2. Optimize PHP applications:Since there are multiple php-cgi processes taking up a lot of CPU and memory, you may need to optimize your PHP application or script to reduce resource consumption.
  3. Limit the number of processes:Consider using something like nginx's worker_processes or PHP-FPM's pm setting to limit the number of processes.
  4. Resource extension:If optimization still doesn't meet your needs, you may need to upgrade your VPS to a configuration with more cores or more RAM.
  5. Monitor and analyze:Use more advanced monitoring tools to analyze system resource usage and identify bottlenecks.
  6. Load balancing:If traffic is part of the problem, consider using load balancing to spread requests across multiple servers.

Before considering upgrading your VPS, it is strongly recommended that you optimize your system and applications first.

Upgrading hardware resources should be done as a last resort and only when it is determined that the current hardware cannot be optimized to meet the needs.

How to set VPS process limit?

When setting process limits, you should consider the following factors:

  • Current number of processes:You need a reasonable process limit that is higher than the current average number of processes to avoid affecting normal operation.
  • System and application requirements:Understand how many processes your system and applications typically require to run.
  • Resource usage:Monitor CPU and memory usage to determine reasonable process limits and avoid resource exhaustion.
    Given the current number of processes on your server, it is recommended not to set the process limit too low.

A looser limit, such as 50 or 100 for a soft limit and 100 or 200 for a hard limit, might be more appropriate. You can adjust this based on your server's load and performance.

If you decide to change process limits, monitor your server's performance closely and be prepared to roll back the changes in case there is an outage. At the same time, consider optimizing application and system configurations to reduce the number of unnecessary processes.

OnLinuxsystem, you can pass /etc/security/limits.conf File settings limit the number of open files, the format is as follows:

<用户名或用户组> soft nofile <软限制值>
<用户名或用户组> hard nofile <硬限制值>

Assuming process limits are set:

elo hard nproc 1000
elo hard nofile 5000

VPS upgraded from 4-core 16GB to optimal configuration plan

It is observed that there are about 500 processes running at most, so is it necessary to upgrade the server configuration? What server configuration is recommended to upgrade to?

Assuming that your application does need to run a large number of processes simultaneously, and you want to ensure that the system has enough resources to handle the high load, here are some specific recommendations:

  • Number of CPU cores:Upgrade to a CPU with 8, 16, or more cores, depending on whether your application can benefit from multi-threading.
  • memory size:Increase the memory to 32GB, 64GB, or higher, depending on your application's memory requirements and the number of processes you are running.
  • Additional resources:Consider adding additional resources, such as a dedicated database server or load balancer, to improve overall performance and reliability.

Keep in mind that upgrading your hardware configuration isn't the answer to performance issues. Make sure your application code, database queries, and server configurations are optimized to take full advantage of the additional hardware resources.

Comment

Your email address will not be published. Required fields * Callout

Scroll to Top