How to Troubleshoot Common Linux VPS Issues: CPU, Memory, Disk Usage
Troubleshoot and fix high CPU, RAM, or disk usage on your Linux VPS using top and other native tools. Boost server speed and prevent performance issues.
Join the DZone community and get the full member experience.
Join For FreeLinux, for its reputation of stability, security, and efficiency, several of the internet is hosted on Linux-based cloud servers, web hosts, and enterprise applications. This reliability positions it ideal for Virtual Private Servers (VPS), where even during high-demand workloads, it remains operational.
Linux has native tools that are very powerful for diagnosing and solving your issues in no time. The commands such as top
, htop
, vmstat
, and sar
are used to monitor the system resources in real-time so that the performance bottleneck can be identified and corrective action can be taken before your VPS starts to freeze.
Read below to understand the most common Linux VPS performance problems to troubleshoot and show how to keep your server running at full throttle.
Basic Commands To Troubleshoot Common Linux Issues
Before we get into the deep of the “Big 3”, let’s highlight a few basic Linux commands to check the performance issues:
top
– Shows current statistics on your CPU and memory and the processes utilizing themfree -m
–Displays memory allocated and consumed in MBdf -h
–Reports disk space usage in human-readable formatdu -sh /path/to/directory
–Provides a relative path to disk use for a given directorysar
– Gathering and reporting activity within the system to give historical performance.
Familiarity with these commands will spare you hours of fruitless effort. Now here are the three big performance killers and ways to troubleshoot them.
The "Big 3" (CPU, RAM, and Disk I/O)
Three factors affect your VPS performance.
- CPU usage – Shows availability of processing power
- Memory (RAM) usage - The more RAM your VPS utilizes, the fewer processes it can cope with.
- Disk I/O (Input/Output) - Affects the reading / writing speed.
All of these lead to performance degradation when not monitored and tuned well, you can use monitoring tools to optimize your performance.
Let’s analyze each in detail.
Checking CPU Usage With Top
The number of processes that can run simultaneously on your VPS is determined by the number of CPU (Central Processing Unit). Your server works extra hard when there is a high CPU load, which results in longer response times and may even cause your applications to stop responding.
Indicators of High CPU Usage
- Pages load slow or (often) timeout.
- SSH connections are slow after a certain amount of time or don’t respond at all.
- Processes get queued, and it leads to some delays in execution
- Even for basic commands, the system feels terribly slow.
How to Check CPU Usage?
You can see live CPU usage with the top
command.
Here’s what to focus on:
- CPU: CPU Percentage utilized by each process
- Load Average: The three numbers on the upper right corner displays the system load average for the past 1, 5 and 15 minutes. This generally indicates a load average higher than the CPU, i.e., the system has a heavier load than is placed on the system.
Identifying Problematic Processes
You will find out if one process is hogging the CPU in the %CPU
column. To find out more details:
ps -eo pid,ppid,cmd,%cpu --sort=-%cpu | head
How to Fix High CPU Usage?
a.) Identify and Kill Problematic Processes
Stop a process that's overusing CPU resources:
kill -9 <PID>
Or restart the service:
systemctl restart <service>
b.) Limit CPU Usage for Processes
For processes that you know will use a lot of CPU (like MySQL, or Apache), try limiting how much of your resources they burn with:
cpulimit -P /usr/bin/apache2 -l 50
c.) Optimize Your Applications
- Caching: Helps here to avoid unnecessary processing (such as Redis to cache database queries)
- Change scripts to be less CPU intensive.
- Limit the background processes that use CPU unnecessarily.
d.) Upgrade CPU Resources
In this case, opt for more CPU cores if your VPS constantly struggles with CPU-heavy workloads.
RAM Usage: Your Server’s Short-Term Memory
The RAM (random access memory) is what enables your VPS to run several processes at the same time. Your system begins to use swap space, which is considerably slower than RAM, when you run out of RAM.
Indicators of High RAM Usage
- High swap usage (free -m shows little or no available RAM).
- Out of memory (OOM) errors crash processes.
- Apps needing more data, like MySQL or those using PHP, become pretty slow.
- More disk I/O because of too much swapping
How to Check Memory Usage?
Use the free command to view the memory status:
free -m
Example output:
total used free shared buff/cache available Mem: 4096 3800 296 100 512 500 Swap: 2048 1980 68 |
- If this says that your "available" memory is too small (<500MB), your VPS is running out of RAM.
- If you are getting a lot of use out of swap, your system is using slow disk-based memory.
For a real-time view, use:
top
or
htop
The processes using the most memory are listed at the top of the list.
How to Fix High RAM Usage?
a.) Find and Kill RAM-Hogging Processes
Identify Processes That Are Overusing Memory:
ps aux --sort=-%mem | head -10
Kill unnecessary ones:
kill -9 <PID>
b.) Clear Cached Memory
Clears cache memory safely (without affecting any running application).
sync; echo 3 > /proc/sys/vm/drop_caches
c.) Increase Swap Space
Extend swap if your server exchanges memory a bit often.
dd if=/dev/zero of=/swapfile bs=1M count=2048
mkswap /swapfile
swapon /swapfile
d.) Optimize Applications
- Combine PHP and MySQL memory usage (
my.cnf
) Settings - Regenerate periodically to fix memory leaks
systemctl restart apache2
e.) Upgrade RAM
If you spend your day constantly over the available RAM, upgrade your VPS to a higher memory plan.
3. Disk Space Problems
The Disk I/O (Input/Output) determines the speed of reading and writing data to storage on your VPS. Slow databases, file transfers, and how quickly an application loads usually come down to poor disk performance.
Symptoms of High Disk I/O Usage
- File read/write operation becomes too slow.
- Database request response times incrases than normal.
- In top or vmstat, high wa (I/O wait time) can be noticed.
- Often "disk full" errors appear.
How to Check Disk I/O Usage?
a.) Monitor Disk Usage
df -h
- If usage is more than 90%, release space.
- Identify which files or directories are using the most disk space with this command:
du -sh /*
b.) Check Disk I/O Performance
To monitor disk I/O performance, use the following command:
iostat -x 5 10
Have a look at the await
and %util
columns. If the %util
is above 80%
, the disk is likely struggling to handle the workload.
How to Fix High Disk Usage?
1. Delete Unnecessary Files
Find and remove large files:
find / -type f -size +500M
2. Clear log files
rm -rf /var/log/*
3. Optimize Disk I/O Usage
- Reduce the read/write operations by enabling MySQL query cache.
- Temporary Files → use tmpfs to lessen the disk writes
- Serve static files through a Content Delivery Network (CDN) to minimize disk reads.
4. Upgrade to SSD Storage
Switching from HDD to SSD can drastically make a difference to your VPS speed if your VPS is using traditional HDD storage.
Step-by-step Troubleshooting Guide
You should troubleshoot your Linux VPS when it displays errors. A proper troubleshooting process will help you determine the cause of the issue so you can give the right fix instead of simply rebooting your server or upgrading your resources.
Here’s a step-by-step guide to troubleshoot problems commonly seen with VPSs.
Step 1: Verifying Resources
Checking the usage of system resources is the first step you should take if you are facing performance issues. Most of the time, server slowdown happens because the overloaded CPU, memory gets exhausted, or the disk I/O turns high. Check these metrics regularly and know what is exactly causing the server to slow down.
How to Check Resource Usage?
Connect to your VPS via SSH
ssh user@your-server-ip
Run Top
to See How Much Memory and CPU Are Being Consumed
- Focus on the two columns
%CPU
and%MEM
which represent processes with the highest resource usage. - Restart or optimize a process if it is using too much CPU or RAM
Use vmstat
For An Overview of theWhole System
- It shows CPU, memory, and disk I/O usage every 5 seconds on 10 iterations.
- If you notice a higher wa (I/O wait time), it means you are going to have disk bottlenecks.
Scan For Large Files Taking Up Disk Space
du -sh /*
- If your disk is almost full, delete old logs and remove any files that you no longer need.
Think For Resource Optimization or an Upgrade
- If your VPS regularly pushes the limits of CPU, RAM, or disk space, tweak applications to consume fewer resources.
- Upgrading to a higher tier VPS plan with increased resources is another option if optimizations have failed to alleviate the issue.
Step 2: Fixing Network Problems
If your VPS is unreachable, then there may be an issue with network configurations or firewall rules. Downtime, slow responses, or failed connections to external services result from network issues.
How To Troubleshoot Network Problems?
- Verify Network Interface Configurations
ip addr show
Ensure your network adapter is active and has the correct IP address assigned.
- Check the firewall and port configuration
- Check active firewall rules
sudo ufw status
- If you are blocking any real service, then you can allow it by using:
sudo ufw allow <port_number>
- For deeper technical investigation, you can use:
sudo iptables -L -n -v
- Perform a Ping Test for Connectivity
ping -c 5 google.com
- Your server might have connectivity or DNS related issues if you lose packets.
- Restart the network service:
sudo systemctl restart networking
- Verify Port Accessibility with nmap
nmap -p <port_number> your-server-ip
- If the port needed is the other way around, make sure the service is run ( Apache, MySQL… )
sudo systemctl status apache2
- Most connectivity issues can be fixed on your Linux VPS by systematically going through network settings and firewall rules and checking if the port is bound by xprocess.
Step 3: Secure Your VPS To Ensure Stability For The Long Term
Security is an essential aspect of managing a VPS. Compromised / Misconfigured Server may run out of speed and stability, or it may be hacked/penetrated. By taking steps to secure your server, you are ensuring that it will not only remain secure, but perform well.
How to Secure Your Linux VPS?
System and Software Update
- Buggy, old software can be a security risk through exploits, and slowdowns
- Regularly update your packages
sudo apt update && sudo apt upgrade -y
Authentication Based On SSH Key Instead Of Password
- Brute-force attacks can easily crack password-based authentication
- Use key authentication to secure your SSH access
ssh-keygen -t rsa
- Copy the key to your VPS
ssh-copy-id user@your-server-ip
Configure a firewall to disallow external attempts to access it
- Configure UFW (Uncomplicated Firewall) to limit any unnecessary incoming connections
sudo ufw allow ssh
sudo ufw allow http
sudo ufw enable
Monitor and Disable Bad Login Attempts
Fail2Ban
, an intruder defense system that short-circuits invadersby blocking repeated failed logins.
sudo apt install fail2ban -y
- Enable protection for SSH
sudo systemctl start fail2ban
Make A Habit Of Backing Up Your VPS Data
- At any point, if you mess up (your server crashes, gets a malware, or is deleted by accident), your backups bring things back to normal.
- Copy data over rsync, create a backup to the other server
rsync -avz /your/data/path user@backup-server:/backup/location
Implementing these security best practices can help to mitigate the potential for cyber threats while promoting seamless operation of your VPS, free from unforeseen interruptions.
How Can Troubleshooting Techniques Solve the Above Problems?
By following these steps, you can significantly enhance the performance of your VPS. Here's how those troubleshooting techniques help you:
- Reduced CPU usage protects you from slow response times.
- By freeing up the RAM, the applications can run smoothly.
- Disk management is essential for maintaining stability in the system.
- In-depth monitoring enables you to detect problems before they become an issue.
Thus, regular maintenance and troubleshooting are the key elements to keep your Linux VPS running smartly.
Conclusion
Since nothing is perfect, you will face problems with your VPS, which is part of server management. However, you can solve many issues quickly and efficiently if you know what to do. But when you follow the troubleshooting steps in this guide, you will be prepared to troubleshoot CPU overload, memory exhaustion, disk space problems, and network connectivity problems to make your VPS stable and responsive.
Opinions expressed by DZone contributors are their own.
Comments