Using the 'top' command to troubleshoot your website

The affects of Web Hosts on Your Business Website

Here're ways your choice of web hosting service provider impacts the performance of your business:


check

Website loading speed

check

Uptime and availability

check

Customer support

check

Security

check

Server location

Using the ‘top’ command to troubleshoot your website

Using the ‘top’ command to troubleshoot your website

'top' command

Overview

The top command allows you to see the status of system tasks in real-time. It gives you a fast overview of your system so you can see if anything pops out that could be causing problems with your website or server. For more information, see the following man page:

linux.die.net/man/1/top

How do I run the ‘top’ command?

To use the ‘top’ command, you must first log into your server using SSH. For instructions on how to create a Shell user and log into your server, see the following articles:

Shortcuts

SSH overview: Creating a user with Shell (SSH) access
There are a few shortcut keys accessible at the top of the screen that change the way the information is displayed:

# Quick fix Key Description
c Changes whether the COMMAND column displays the ‘top’ command or the program name.
t Turns on and off the summary information display.
m Turns on and off the display of memory information.
The display is sorted by the top users of various system resources. Useful for quickly identifying the system’s performance-hungry processes.
f Opens the top interactive setup screen. It’s useful for putting together a top for a specific purpose.
o Allows you to select the top-level ordering interactively.
r executes the renice ‘top’ command.
k executes the kill command.
z toggles between color and monochrome.
This is the first step in the process. Often, merely monitoring your active processes will reveal which site is creating problems. Check which processes are running by logging into your server using SSH. Let’s imagine you come upon something similar to this:

[server]

$ top -c top – 14:37:35 up 10 days, 17:35, 3 users, load average: 0.83, 0.89, 1.11 Tasks: $ top -c top – 14:37:35 up 10 days, 17:35, 3 users, load average: 0.83, 0.89, 1.11 1 is running, 15 is sleeping, 0 is stopped, and 0 is a zombie.
34.7 percent us, 4.8 percent sy, 1.7 percent ni, 56.5 percent id, 0.9 percent wa, 0.2 percent hi, 1.1 percent si, 0.0 percent st, 34.7 percent us, 4.8 percent sy, 1.7 percent ni, 56.5 percent id, 0.9 percent wa, 0.2 percent hi, 1.1 percent si, 0.0 percent st
32966092k total memory, 32546460k used memory, 419632k free memory, 6369232k buffers
8000328k total, 228972k used, 7771356k free, 12650516k cached Swap: 8000328k total, 228972k used, 7771356k free, 12650516k cached

PID USER PR NI VIRT RES SHR S percent PID USER PR NI VIRT RES SHR S percent

% of the CPU

TIME TO REMEMBER+ php5.cgi 10895 username 20 0 65940 10m 6848 S 0 0.0 0:00.92 php5.cgi 10917 username 20 0 65980 10m 6848 S 0 0.0 0:00.79 php5.cgi 7542 username 20 0 65956 10m 6860 S 0 0.0 0:00.79 51 php5.cgi 7818 username 20 0 65980 10m 6860 S 0 0.0 0:00.35 php5.cgi 7828 username 20 0 65988 10m 6860 S 0 0.0 0:00.33 php5.cgi 7917 username 20 0 66016 10m 6860 S 0 0.0 0:00.43
If it looks like the image above, you’re most certainly dealing with this issue. In general, if you’re running more than 10 PHP processes at once and they’re all quite stable, you’re dealing with memory concerns.

This might help you troubleshoot a problem on a single site under your login, but if you have multiple sites, you should run lsof to see if there are any open files that could be causing a problem.

Sort results by memory usage

The top results can be sorted by memory use. To see the live results, first run the ‘top’ command.

When the program is opened, press Shift + m to sort the output by memory usage.

Displaying memory usage of a specific process 

$ grep -i | top -b -n 1 [EnterProcessName]
VPS and Dedicated Servers
Running top on a VPS or Dedicated Server will show you a number of system processes operated by users like ‘root,’ ‘dhapache,’ and ‘postfix,’ among others. Use the following command to examine only the processes that are being run by a given user.