Understand resource limits
A Python application does not only fail because of a bug. It can run out of memory, be slowed by a CPU limit, or be unable to write to disk. Telling these three cases apart prevents random plan upgrades.
1. Three resources, three symptoms
| Resource | Typical symptom | Measurement |
|---|---|---|
| RAM | process killed, exit code 137, MemoryError |
free -m, ps, memory.events |
| CPU | slow responses, timeouts, growing queue | top, ps, response time |
| Disk | write failures, corrupted database, interrupted logs | df -h, du |
An application may use little on average and a lot at peak: importing a large file, generating PDFs, a query without pagination. Size for the peak, not for idle.
2. Measure and recognize exhaustion
On a Debian VPS, the basic commands:
free -m
ps -eo pid,comm,%cpu,%mem,rss --sort=-rss | head -n 10
df -hInside a system container, cgroup counters show the real limit. On a cgroup v2 system:
cat /sys/fs/cgroup/memory.max
cat /sys/fs/cgroup/memory.current
cat /sys/fs/cgroup/memory.eventsA rising oom_kill counter confirms a process was killed for lack of memory. Exit code 137 means SIGKILL, often sent by the kernel. A CPU limit, by contrast, does not kill the process: requests slow down and timeouts increase, but the service stays alive. On application hosting, the console and panel graphs show usage; a restart after a memory spike is a strong clue.
3. Reduce consumption
- Stream instead of loading everything: read files in chunks, stream large responses.
- Paginate: never load a whole table; use
LIMITandOFFSET. - Workers: every Python process has its own memory. Four workers cost roughly four times the baseline.
- Bounded caches: set a maximum size and an eviction policy, or the cache becomes a leak.
- Logs: rotate them and keep
INFOin production. - Old data: archive or compress what is no longer read.
Measure before and after every change. Without a baseline, no optimization is verifiable.
4. Choose the plan
| VPS plan | RAM | Reasonable use |
|---|---|---|
| Free | 512 MB | tests, small bot, static site |
| Basic | 2 GB | light API, one Python service |
| Pro | 4 GB | several services, local database |
| Business | 8 GB | heavier load, multiple workers |
On application hosting, resources depend on the selected plan. Compare on the pricing page and keep headroom: a temporary spike must not trigger an OOM.
5. Verify
- Record usage at idle, then under real load.
- Check
memory.eventsafter a day of traffic. - Test the heaviest scenario before paying for an upgrade.
- Watch disk space: logs and temporary files are the first suspects.
Advertisement
Was this article helpful?
Read next
- Use a Python virtual environmentIsolate dependencies with venv, then adapt the method to managed hosting and a VPS.
- Back up application dataInventory, copy consistently, move the backup offsite and test the restore.
- Read Python application logsUnderstand stdout, stderr, the logging module and tracebacks in the panel console.