Dealing with High CPU or Memory Usage on your WordPress Server

Content Error or Suggest an Edit

Notice a grammatical error or technical inaccuracy? Let us know, we will give you credit!

Draft Warning

You’ve reached a draft 🤷‍♂️ and unfortunately, it’s a work in progress.

SSH and Linux Shell Knowledge Required

This article requires a basic understanding of connecting to a server through SSH and issuing Linux Shell commands using Bash.

Identifying High CPU or Memory Usage

This article will assist you in identifying high CPU usage on your server (VM, Baremetal) that hosts one or multiple WordPress sites.

Now, I won’t talk about identifying if your server has a problem with High CPU usage. You can usually figure this out from your provider’s usage graphs, control panel usage graphs, or alerting. For instance, GridPane provides an alert when your server suffers from a high CPU load.

1. Linux ps Command

This command lets you view all the processes and threads on a Linux system in a tree view. The default output of running the command provides limited information, so you’ll want to use the following commands.

List all Processes

ps -auxwwf
  • -a = Select all processes except both session leaders (see getsid(2)) and processes not associated with a terminal.
  • -u = Display user-oriented format.
  • -x = this option causes ps to list all processes owned by you (same EUID as ps), or to list all processes when used together with the a option.
  • -w = Wide output. Use this option twice for unlimited width.
  • -f = Do full-format listing.
Output of ps -auxwwf

List Top 15 CPU Processes

ps -auxwwf | sort -nrk 3,3 | head -n 15
  • We’re using the same ps -auxwwf as above.
  • sort -nrk 3,3
    • -n = numeric sort
    • -r = reverse the result of comparisons
    • -k = sort via a key; KEYDEF gives location and type
    • 3,3 = column 3, data 3
Output of the Linux ps command piped through sort and head.

2. Linux top and htop Command

Linux “top” command

The top command in Linux will provide you with a real-time view of the running processes on a system and refresh every 3 seconds. It’s a great tool when you quickly need to figure out what is going on resource-wise on a Linux system.

You can press “shift + ?” to get to the help screen, which provides instructions on how to control the output, including sorting based on fields such as %CPU

The top (table of processes) command shows a real-time view of running processes in Linux and displays kernel-managed tasks. The command also provides a system information summary that shows resource utilization, including CPU and memory usage

Linux top command
Linux top command help

Linux “htop” command

The Linux htop command is top on steroids, providing some improvements to the top command such as color, displaying of CPU cores/Memory as usage graphs.

Htop is an interactive real-time process monitoring application for Linux/Unix-like systems and also a handy alternative to top command, which is a default process monitoring tool that comes pre-installed on all Linux operating systems.
Linux ‘htop’ command output

Typically htop is whatever one recommends and uses due to its easy-to-read UI. However, there is one caveat, CPU steal isn’t displayed by default and has to be turned on.

This GitHub issue explains how to enable “Detailed CPU time”, and then how to change the CPU graph from bar to text. You can also add the “CPU Average” meter and change it to text as it’s smaller

Here’s what it looks like once you make the change.

htop with detailed CPU time.

Another caveat is that you can’t display processes in tree view and sort on CPU usage, which is understandable.

Installing htop

The “htop” package is available on most modern Linux distributions as the package “htop”. For Ubuntu/GridPane folks you can install it using the following command.

apt-get install htop

Tracking High CPU Usage

Now that you’re familiar with reviewing your server’s high CPU usage in real-time, what about tracking which CPU usage over time? Enter atop

Linux ‘atop’ command

The Linux atop command is a small and efficient tool for logging snapshots of your system in a top-like format over time. Allowing you to review your server’s processes back in time.

Atop is an ASCII full-screen performance monitor which can log and report the activity of all server processes. One feature I really like is that atop will stay active in the background for long-term server analysis (up to 28 days by default).
atop command output

Installing atop

The “atop” package is available on most modern Linux distributions as the package “atop”. For Ubuntu/GridPane folks, you can install it using the following command.

apt-get install atop

Configuring atop

Once atop is installed, you will need to ensure that it is running as a service and that it starts on boot if your server is rebooted.

systemctl enable atop
systemctl start atop

By default, atop will take a snapshot every 600 seconds; you may want to bring this down to 300 seconds which you can do so by running the following command.

sudo sed -i -e 's/INTERVAL=600/INTERVAL=300/g' /usr/share/atop/atop.daily
sudo systemctl restart atop

Viewing atop History

You can view the historic data of atop through SSH by running the atop command and providing an atop raw data file. The raw data files are located in /var/log/atop, you’ll see that there is a file generated for each day.

A screenshot of the /var/log/atop directory containing atop_(date) files.

Once inside the /var/log/atop directory, you can then use the atop command with the -r switch to read an atop raw data file.

atop -r atop_20221123
Screenshot of atop reading a raw data file.

As you can see from the screenshot above, quite a bit of data is shown. You’ll notice on the top left-hand side the date and time. You can move forward and backwards using the following keys:

  • t – Show next.
  • T (Shift +t) – Show previous.

If you have the date and time of the spike in resources, you can find out what processes were running at that time and hopefully find a culprit that caused the resource increase.


You might have heard about Netdata; free software runs an agent on your server to collect operating system metrics. The agent reports back to the where it’s processed, graphed out, and if there’s an issue, an email alert is sent out.


  • 11-23-2022 – Renamed article to include memory as well as CPU. Added section on reading atop history.
You May Also Like