GEARFLOW LAB // DOCKER COMPOSE & VPS RAM UTILITY 100% Client-Side JS · Zero Ads · Zero Telemetry

Docker Compose & Self-Hosted AI Stack RAM, Swap & VPS Sizing Calculator

Sum empirical container peak RSS across n8n, PostgreSQL, PgBouncer, Redis, Nginx, OpenObserve, and Ollama, add Linux kernel slab and page-cache reserves, prevent cgroup Exit Code 137 OOM kills, export hardened docker-compose.yml and zram-generator configs, and compute Cloud VPS vs. local Mini PC break-even TCO.

Quick Stack Presets:

1. Select Container Stack & Host Limits

6 services active
100 conns

2. Host Memory Budget, OOM Verdict & Production Configs

Recommended Safe Tier: 4 GB RAM (3.34 GiB Required) 3,422 / 4,096 MiB (83.5%)
6 active services peak at 1,956 MiB RSS plus 420 MiB Ubuntu 24.04 kernel, 256 MiB page cache, and 790 MiB (30%) OOM headroom. ZRAM absorbs cold anonymous pages before Exit Code 137 triggers.
Safe RAM Budget
3,422 MiB
3.34 GiB w/ 30% headroom
Container Peak RSS
1,956 MiB
6 services @ 100 conns
OS + Page Cache
676 MiB
420 kernel + 256 cache
Recommended Tier
4 GB VPS
ZRAM swap: 2,048 MiB
Proportional Host RAM Allocation vs Recommended Physical Tier 3,422 MiB / 4,096 MiB ceiling
Kernel + Slab: 420 MiB Page Cache Reserve: 256 MiB Container Peak RSS: 1,956 MiB Headroom Buffer: 790 MiB

Physical RAM Tier Evaluation (Exit Code 137 OOM Prevention)

PgBouncer saves 738 MiB Postgres RSS
Physical RAM Tier Capacity Active Load With Headroom OOM Safety Verdict
2 GB Cloud VPS 2,048 MiB 128.5% 167.1% OOM Risk (Exit 137)
4 GB Cloud VPS 4,096 MiB 64.3% 83.5% Recommended Safe Tier
8 GB Cloud VPS 8,192 MiB 32.1% 41.8% Safe (Ample Headroom)
16 GB Cloud VPS 16,384 MiB 16.1% 20.9% Safe (Ample Headroom)
32 GB Cloud VPS 32,768 MiB 8.0% 10.4% Safe (Ample Headroom)
Local Mini PC (32 GB-64 GB) 32,768+ MiB 8.0% 10.4% Safe (Local Dedicated)

Linux zram-generator & VM OOM Guard (sysctl)

# Target Host: Ubuntu 24.04 LTS on 4 GB RAM (ZRAM Enabled: 2048 MiB zstd)
sudo apt-get update && sudo apt-get install -y systemd-zram-generator
sudo tee /etc/systemd/zram-generator.conf >/dev/null <<'EOF'
[zram0]
zram-size = min(ram / 2, 8192)
compression-algorithm = zstd
swap-priority = 100
EOF

sudo tee /etc/sysctl.d/99-gfl-docker-memory.conf >/dev/null <<'EOF'
vm.swappiness = 10
vm.overcommit_memory = 0
vm.vfs_cache_pressure = 50
vm.panic_on_oom = 0
EOF
sudo systemctl daemon-reload && sudo systemctl start systemd-zram-setup@zram0.service
sudo sysctl --system

Hardened docker-compose.yml (127.0.0.1 + Cgroup Limits)

# Hardened Compose v2 Stack (127.0.0.1 loopback bindings, cgroup mem_limit, pids_limit, 10m log cap)
services:
  n8n:
    image: docker.n8n.io/n8nio/n8n:1.81.4
    restart: unless-stopped
    ports:
      - "127.0.0.1:5678:5678"
    mem_limit: 1024m
    memswap_limit: 1280m
    pids_limit: 256
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"

Cloud VPS Monthly Cost vs. Local Mini Server Break-Even TCO

3-Year (36 mo) · 18W @ $0.16/kWh = $2.10/mo
Reference Cloud VPS Tier Cloud Total Matched Local Mini Server Local TCO (HW + Power) Break-Even
4 GB Cloud VPS (~$24/mo) $864 (36 mo) 16 GB Mini Server ($599 + $2.10/mo) $675 27.4 months
8 GB Cloud VPS (~$48/mo) $1,728 (36 mo) 16 GB Mini Server ($599 + $2.10/mo) $675 13.1 months
16 GB Cloud VPS (~$96/mo) $3,456 (36 mo) 16 GB Mini Server ($599 + $2.10/mo) $675 6.4 months
32 GB Cloud VPS (~$192/mo) $6,912 (36 mo) 32 GB Mini Server ($799 + $2.10/mo) $875 4.2 months

Reference formula: months_to_breakeven = hardware_upfront / (cloud_monthly - 2.10) using transparent unbundled x86/ARM64 cloud memory rates and 18W * 24h * 30.44d / 1000 * $0.16/kWh = $2.10/mo continuous wall power. Zero vendor sponsorships or affiliate links.

Why Multi-Container Self-Hosted Stacks Hit Linux Exit Code 137

Sizing a Linux host from idle docker stats numbers fails under webhook concurrency. When a Node.js workflow worker, PostgreSQL backend pool, and log shipper spike simultaneously, anonymous heap pages cannot be evicted like clean filesystem cache. Once host or container memory crosses the Linux kernel cgroup v2 memory.max boundary, the kernel Out-Of-Memory killer sends SIGKILL (signal 9) and terminates the process with Exit Code 137 (128 + 9), as reproduced in our Docker Exit Code 137 OOMKilled vs SIGKILL lab.

Two architectural controls keep small and mid-sized servers stable without overpaying for idle RAM. First, multiplexing n8n Queue Mode workers through PgBouncer in transaction mode caps active PostgreSQL shared and per-backend memory (cutting 450-client backend RSS from 739.5 MiB down to 84.8 MiB in our PostgreSQL & PgBouncer Docker benchmark). Second, configuring a compressed RAM block device via the Linux kernel zram driver with zstd compression absorbs cold Node.js and Python heap pages in sub-millisecond RAM instead of stalling on slow NVMe swap.

In production Compose deployments, pair host ZRAM with explicit per-service Docker Engine memory and swap constraints (mem_limit, memswap_limit, and pids_limit) so a single runaway build or log spike never starves PostgreSQL or SSH. Always attach bounded Docker json-file log rotation (max-size: "10m") and bind internal database, Redis, and agent ports to 127.0.0.1 so Docker NAT rules cannot bypass host firewalls.

Docker Compose RAM, ZRAM Swap & VPS Sizing FAQ

Why should every Docker Compose service set mem_limit and pids_limit?

Without per-container cgroup limits, one memory leak in a webhook worker or observability collector can exhaust host RAM and trigger a kernel OOM kill against PostgreSQL. Setting mem_limit and pids_limit isolates fault domains to the offending container.

Does ZRAM replace physical RAM for active PostgreSQL shared_buffers or LLM weights?

No. Hot database pages and quantized LLM tensors are read continuously and do not benefit from swap compression. ZRAM is strictly an in-RAM safety cushion for cold anonymous pages (idle Node.js workers, systemd services, and burst buffers) with vm.swappiness=10.

When does a local Mini PC beat a monthly Cloud VPS on total cost of ownership?

Once a self-hosted AI or observability stack needs 16 GB to 32 GB of RAM (~$96 to $192/mo on unbundled cloud instances), a $599 to $799 ARM64 or x86 mini server drawing 18W (~$2.10/mo at $0.16/kWh) reaches break-even in 4.2 to 6.4 months.

VERIFIED LAB BENCHMARKS & COMPANION UTILITIES

Related Docker, PostgreSQL & Self-Hosted Playbooks

Docker Exit Code 137: OOMKilled=true vs SIGKILL Lab →

Inspecting cgroup memory limits, kernel dmesg traces, and container stop timeouts.

PostgreSQL & PgBouncer Docker Pool Benchmark →

Cutting 450-connection backend memory from 739.5 MiB down to 84.8 MiB in Compose.

Why Docker Bypasses UFW on Ubuntu (127.0.0.1 Fix) →

Preventing PREROUTING DNAT exposure on ports 5432, 6379, 5678, and 11434.

OpenObserve Docker Benchmark: 288 MiB RAM & 100k Logs →

Lightweight single-binary log ingestion and bind-mount UID troubleshooting.

Self-Host n8n + Ollama in Docker Compose →

Bridge DNS service discovery and fixing container 127.0.0.1:11434 ECONNREFUSED errors.

All 8 Engineering Utilities & Tools Hub →

Explore prefilled scenarios for PgBouncer, Nginx SSE, Compose v2, LLM VRAM, and Mac 5K2K PPI.