Server Administration

How to Reduce Server Resource Usage: Practical Tips for CPU, RAM and Disk

By NileVPS Team · Published · 4 min read

اقرأ المقال بالعربي

A server that wastes resources costs more than it should and has less headroom for real traffic. Many VPS installations run services nobody uses, keep too many worker processes alive, and recompute the same pages thousands of times a day. The good news is that most savings come from a few simple changes. This guide walks through practical steps to reduce CPU, memory, disk and bandwidth usage on a Linux server, in the order that usually gives the best results.

Step 1: measure before you change anything

Optimization without measurement is guessing. Record a baseline first:

uptime
free -h
df -h
ps -eo pid,pcpu,pmem,rss,cmd --sort=-rss | head -15
systemd-cgtop            # resource usage grouped by service

Note peak and idle values, ideally over a full day with a monitoring tool. Then change one thing at a time and compare. If you are not sure which resource is the limit, start with our guide to finding server bottlenecks.

Step 2: remove what you do not need

Every running service uses memory, and many wake up regularly to use CPU.

systemctl list-units --type=service --state=running
systemctl disable --now <service-name>

Common candidates on a web server: a desktop environment installed by mistake, mail servers you do not use, print services, unused database engines, old application versions, and leftover test containers (docker ps -a, docker system df). Remove packages you no longer need with apt autoremove or dnf autoremove, after checking the list it proposes.

Step 3: right-size worker processes

Application servers usually start a pool of workers. Too many workers waste RAM and can push the server into swap; too few cause queuing.

For PHP-FPM, a reasonable approach is:

  1. Measure the average memory of one worker: ps -C php-fpm8.2 -o rss= (adjust the name to your version).
  2. Decide how much RAM you can give PHP after the database and OS.
  3. Set pm.max_children to roughly that budget divided by the per-worker size.
  4. On low-traffic sites, pm = ondemand with pm.process_idle_timeout = 10s frees memory when idle.

The same idea applies to Gunicorn, Puma, Node.js clusters and others: tie the worker count to the available cores and memory, not to a number copied from a tutorial.

Step 4: cache aggressively

Caching avoids doing the same work twice and is often the single biggest saving.

LayerWhat it savesExamples
Opcode cacheRecompiling PHP on each requestOPcache
Object cacheRepeated database queriesRedis, Memcached
Page cacheRunning the app for anonymous visitorsNginx fastcgi_cache, Varnish
Browser and CDN cacheServing static files repeatedlyCache-Control headers, a CDN

Make sure OPcache is enabled and has enough memory (opcache.memory_consumption), and set long cache lifetimes for versioned static assets.

Step 5: tune the database

Databases are frequently the heaviest process on a small server.

  • Enable the slow query log and fix the worst queries first, usually by adding an index.
  • Size buffers to the server: for MySQL or MariaDB, innodb_buffer_pool_size should fit your working data but leave room for everything else; for PostgreSQL, tune shared_buffers and work_mem with care.
  • Limit max_connections and use connection pooling instead of opening a connection per request.
  • Clean up old rows such as expired sessions, logs stored in tables, and revisions.

Step 6: reduce disk usage and writes

du -xh / --max-depth=2 2>/dev/null | sort -h | tail -20
journalctl --disk-usage
sudo journalctl --vacuum-size=200M

Set limits for the journal (SystemMaxUse= in /etc/systemd/journald.conf), make sure logrotate compresses and rotates application logs, prune old Docker images, and move old backups off the server. Reducing debug logging also lowers disk writes, which helps I/O-sensitive workloads.

Step 7: save bandwidth

  • Enable gzip or Brotli compression for text responses.
  • Serve images in modern formats and at the size they are displayed.
  • Use a CDN for static files.
  • Block hotlinking and abusive bots that crawl aggressively.

Step 8: schedule heavy jobs wisely

Backups, reports and imports should not run at peak time. Schedule them with cron during quiet hours and lower their priority:

nice -n 10 ionice -c2 -n7 /usr/local/bin/backup.sh

Know when to stop optimizing

Once the server is lean, further tweaks bring small gains for real effort. If usage is still near the limit after these steps, upgrading is the sensible choice, and snapshots make it safe to test. You can compare sizes on the pricing page.

FAQ

Is high RAM usage always a problem on Linux?

No. Linux uses free memory for the page cache, which speeds up disk access and is released when applications need it. Watch the "available" value in free -h and swap activity rather than "used".

Will disabling swap save resources?

Usually not. A small amount of swap gives the kernel room to move rarely used pages out of RAM. The problem is constant swapping, which means the server needs less memory usage or more RAM.

How much can caching reduce CPU usage?

It depends on the application and how many requests can be served from cache. For content sites with many anonymous visitors, a page cache can remove most of the application work, but measure your own before and after numbers rather than relying on general claims.

Related guides