High CPU Usage on Digital Ocean Web Server

We have a Laravel website which is currently hosted on Digital Ocean (Nginx). The droplet is a 2 vCPUs, 2 GB Memory, 60 GB SSD, 3 TB transfer running PHP 7.4. We are seeing a steady increase in CPU usage from one day to the next.

We currently have 118 sleeping tasks (which I am not too worried about), however several php-fpm commands are appearing as time passes and at times the total CPU usage spikes to around 50-60%. We already had this site on a different server before Digital Ocean and the CPU was at a constant 95-100%.

Below is a snapshot of the current processes using a hefty amount of CPU which are running on the server. Is this normal for a Laravel site and are these php-fpm commands really required?

top - 11:48:38 up 21 days, 22:46,  1 user,  load average: 0.65, 0.75, 0.79
Tasks: 120 total,   2 running, 118 sleeping,   0 stopped,   0 zombie
%Cpu(s): 41.8 us, 21.5 sy,  0.0 ni, 36.4 id,  0.0 wa,  0.0 hi,  0.3 si,  0.0 st
MiB Mem :   1987.6 total,    172.6 free,    291.9 used,   1523.1 buff/cache
MiB Swap:      0.0 total,      0.0 free,      0.0 used.   1475.8 avail Mem

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
 222902 www-data  20   0  242664  58356  37272 R  76.4   2.9   0:13.28 php-fpm: pool www
 222903 www-data  20   0  242652  57740  37208 S  26.6   2.8   0:01.80 php-fpm: pool www
 222901 www-data  20   0  242700  57480  37144 S  21.9   2.8   0:24.67 php-fpm: pool www
     11 root      20   0       0      0      0 I   0.3   0.0   5:25.41 [rcu_sched]
 167142 www-data  20   0  141972  15920   5384 S   0.3   0.8  29:09.38 nginx: worker process
      1 root      20   0  171116  12632   7848 S   0.0   0.6   1:28.61 /sbin/init
      2 root      20   0       0      0      0 S   0.0   0.0   0:00.12 [kthreadd]
      3 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 [rcu_gp]
      4 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 [rcu_par_gp]
      6 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 [kworker/0:0H-kblockd]
      9 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 [mm_percpu_wq]
     10 root      20   0       0      0      0 S   0.0   0.0   1:33.28 [ksoftirqd/0]

Note: We currently have Cloudflare enabled on the site and up until the 27th of February, the site was only accessible for the country of shop origin (Malta). Up until that point, Digital Ocean graphs show that the CPU usage went up to 4.5% at most. After the 27th, we opened up the site to roughly 20 more countries - some in EU, Australia and US, and immediately saw this spike in CPU usage.

My concern is that as time passes and site traffic is increased, the CPU might reach a point of no return and (as previously experienced) site would unfortunately be unbrowseable.

Any help, tips and advise is greatly appreciated.

Thanks in advance :)


Laravel is not especially lightweight. You need to gather information about what you system is doing, analyse the data and make changes as appropriate.

Look in your web server access logs and your laravel logs as a starting point to determine what activity is happening on the system.

Decide if things really are a problem and then take action.

System resources are there to be used. Your system seems overall lightly used.