Sizing Your Rails App: 1 vCPU vs 2 vCPUs and Knowing When to Upgrade

Sizing a Rails app comes down to two measurements and one rule. Measure how busy the CPU is when requests wait in a queue, and measure how much memory each Puma worker really uses; then remember that, because of Ruby’s global VM lock, one Ruby process can only run Ruby code on one core at a time. With those three facts you can tell whether going from 1 vCPU to 2 vCPUs will make the app faster, or whether the bottleneck is memory, the database or your own code, where more CPU changes nothing. This guide shows exactly what to measure inside a container, the signals that mean it’s time to upgrade, and how to size Puma for the CPU and memory you have.
TL;DR
- More vCPUs help only when the app is CPU-bound: high CPU and requests queueing at peak. If CPU is low but responses are slow, look at the database and external calls first.
- One Puma worker uses at most about one core for Ruby code. With 1 vCPU, run 1 worker (or single mode) with 3–5 threads; with 2 vCPUs, run 2 workers.
- Memory decides how many workers fit: workers × per-worker RSS + overhead must stay under the memory limit with headroom, or the kernel’s OOM killer decides for you.
- Inside a container, read the cgroup files (
cpu.max,cpu.stat,memory.current,memory.events), nottop’s host-wide numbers.- Upgrade when you’ve ruled out the cheap fixes and the signals persist across a normal week, not after one spike.
What does 1 vCPU vs 2 vCPUs mean for a Rails app?
A second vCPU lets a second Ruby process run Ruby code at the same time. It doesn’t make a single request faster; it doubles how many CPU-heavy requests can run in parallel.

The reason is the GVL (global VM lock) in CRuby: within one process, only one thread executes Ruby code at a time. Threads still help a lot, because while one thread waits on PostgreSQL, Redis or an HTTP API, it releases the GVL and another thread runs. So:
| Work in a typical request | Uses the CPU? | Helped by more threads | Helped by more vCPUs |
|---|---|---|---|
| Waiting on database queries | No | Yes | No |
| Waiting on Redis or external APIs | No | Yes | No |
| Rendering views, serializing JSON | Yes | Only up to one core per process | Yes, with more workers |
| Ruby business logic, image processing | Yes | Only up to one core per process | Yes, with more workers |
| Garbage collection | Yes | No | Yes, with more workers |
“vCPU” also means different things on different hosts. A shared vCPU is a share of a physical core with other tenants, often with a quota; a dedicated vCPU is reserved for you. On shared CPUs, the numbers you see in top depend on neighbours and quotas, which is why Step 1 reads the container’s own counters.
Prerequisites
- A Rails 7.2 or 8.x app running with Puma 6 or later in production.
- Shell access to the running container (
docker exec,kamal app exec,fly ssh console, or the platform’s console). - A cgroup v2 host (
ls /sys/fs/cgroup/cpu.maxexists). Most current Docker and platform hosts use cgroup v2. - At least a few days of normal traffic, including your usual peak.
Step 1: Measure CPU usage and throttling
Read the container’s CPU quota and how often it’s been throttled. Throttling means the app wanted more CPU than its allocation in a scheduling period.
# Inside the container
cat /sys/fs/cgroup/cpu.max # "100000 100000" = 1 vCPU quota, "200000 100000" = 2, "max 100000" = no quota
cat /sys/fs/cgroup/cpu.stat # usage_usec, nr_periods, nr_throttled, throttled_usec
nproc # CPUs visible to the process (not always the quota)
To get rates rather than totals since boot, sample twice:
#!/usr/bin/env bash
# bin/cpu-sample: CPU used (in vCPUs) and % of periods throttled over N seconds.
interval=${1:-60}
read_stat() { awk -v k="$1" '$1==k {print $2}' /sys/fs/cgroup/cpu.stat; }
u1=$(read_stat usage_usec); p1=$(read_stat nr_periods); t1=$(read_stat nr_throttled)
sleep "$interval"
u2=$(read_stat usage_usec); p2=$(read_stat nr_periods); t2=$(read_stat nr_throttled)
awk -v du=$((u2-u1)) -v dp=$((p2-p1)) -v dt=$((t2-t1)) -v s="$interval" \
'BEGIN { printf "cpu used: %.2f vCPU throttled periods: %.1f%%\n", du/(s*1e6), (dp ? 100*dt/dp : 0) }'
Run it during your peak hour. cpu used close to the quota (for example 0.95 on 1 vCPU) and throttled periods above a few percent mean the app is CPU-bound at that moment. Low CPU use with slow responses means the time is going somewhere else.
Pro Tip: nproc and Etc.nprocessors often report the host’s cores, not your quota. Don’t let a generated config/puma.rb set WEB_CONCURRENCY from it inside a container; set workers explicitly from your allocation.
Step 2: Measure memory per worker
Measure each Puma worker’s resident memory after it has served real traffic for a while, and the container’s total against its limit.
# Per-process RSS, in MB (master and each worker)
ps -o pid,ppid,rss,cmd -C ruby | awk 'NR==1 {print; next} {printf "%s %s %.0fMB %s\n", $1, $2, $3/1024, substr($0, index($0,$4))}'
# Container total and limit
cat /sys/fs/cgroup/memory.current # bytes in use (includes page cache)
cat /sys/fs/cgroup/memory.max # limit in bytes, or "max"
cat /sys/fs/cgroup/memory.events # look at oom and oom_kill counters
grep -E '^(anon|file) ' /sys/fs/cgroup/memory.stat # anon = process memory, file = reclaimable cache
Read three things from this:
- Per-worker RSS after warm-up: the number that decides how many workers fit. Check it a few hours after a deploy, not right after boot.
- The trend over days: steady growth that never levels off is a leak or unbounded cache, not a sizing problem. The Rails memory leak guide covers how to tell which.
oom_killinmemory.events: any value above zero means the kernel killed a process for exceeding the limit. Requests on that worker were dropped.
Puma’s own stats complete the picture. Enable the control app and query it:
# config/puma.rb
activate_control_app "tcp://127.0.0.1:9293", { auth_token: ENV.fetch("PUMA_CONTROL_TOKEN") }
curl -s "http://127.0.0.1:9293/stats?token=$PUMA_CONTROL_TOKEN"
# {"workers":2,"booted_workers":2,"worker_status":[{"pid":41,"last_status":{"backlog":0,"running":3,"pool_capacity":1,"busy_threads":2,"max_threads":3,...}}, ...]}
A backlog above zero means connections are waiting for a free thread in that worker. busy_threads equal to max_threads most of the time means the workers are saturated.
Step 3: Measure request queue time
Queue time is how long a request waited before a Puma thread started on it. It’s the most direct signal that you need more capacity, because it measures waiting rather than work.
If the proxy in front of the app sets X-Request-Start (Heroku’s router does; Nginx can with proxy_set_header X-Request-Start "t=${msec}";), log the difference:
# app/middleware/request_queue_time.rb
class RequestQueueTime
def initialize(app) = @app = app
def call(env)
if (start = env["HTTP_X_REQUEST_START"])
started_at = start.delete_prefix("t=").to_f
started_at /= 1000.0 if started_at > 1e11 # milliseconds → seconds
queue_ms = ((Time.now.to_f - started_at) * 1000).round
env["queue_time_ms"] = queue_ms if queue_ms.between?(0, 60_000)
end
@app.call(env)
end
end
# config/application.rb
require_relative "../app/middleware/request_queue_time"
module MyApp
class Application < Rails::Application
config.middleware.insert_before 0, RequestQueueTime
end
end
# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
def append_info_to_payload(payload)
super
payload[:queue_time_ms] = request.env["queue_time_ms"]
end
end
With a structured log subscriber (Lograge or Rails 8.1’s structured event logging), queue_time_ms now appears on every request line. A p95 queue time of a few milliseconds is healthy; tens to hundreds of milliseconds at peak means requests are waiting for capacity. If there’s no X-Request-Start header, Puma’s backlog from Step 2 is the fallback signal. The Rails monitoring guide shows how to chart and alert on it.
Step 4: Read the signals
Combine the three measurements before deciding. Each pattern points at a different fix, and only some of them are “add vCPUs”.
| What you see at peak | Bottleneck | Fix |
|---|---|---|
| CPU near quota, throttling > 5%, queue time rising | CPU | Optimize hot paths first; then 2 vCPUs with 2 workers |
| CPU low (< 50%), queue time rising, many threads busy | Threads waiting on I/O | Slow queries or external calls; add threads, fix N+1s, add timeouts |
| CPU low, queue time ~0, p95 latency high | Slow requests, not capacity | Database indexes, caching, moving work to jobs |
oom_kill > 0, workers restarting |
Memory | Fewer workers, find the bloat, or more memory |
| Memory grows for days without levelling off | Leak or unbounded cache | Fix the leak; more memory only delays it |
| Spikes only during deploys or cron-like jobs | Bursty work | Spread the jobs, run them off-peak, or limit their concurrency |
The most common mistake is the second row: CPU is low, the app is slow, and the reaction is to buy more CPU. If threads are waiting on a database, a second vCPU only lets more threads wait. The Rails performance optimization guide covers those fixes, and the request timeout guide keeps one slow dependency from tying up every thread.
When should I upgrade from 1 vCPU to 2 vCPUs?
Upgrade when, across a normal week, peak traffic shows CPU at or near the quota with throttling and rising queue time, and you’ve already fixed the obvious hot spots. Don’t upgrade for a single spike, for slow queries, or for a memory problem. CPU doesn’t fix any of those.
Step 5: Size Puma for the vCPUs and memory you have
Set workers from the vCPUs, threads from how I/O-heavy the app is, and check the result fits in memory.
| Allocation | Puma workers | Threads per worker | Notes |
|---|---|---|---|
| Fractional vCPU (< 1) | 0 (single mode) | 3 | No master process; lowest memory |
| 1 vCPU | 0 or 1 | 3–5 | Single mode saves the master’s memory; 1 worker adds preload_app! and phased restarts |
| 2 vCPUs | 2 | 3–5 | Two processes can run Ruby code in parallel |
| 4 vCPUs | 3–4 | 3–5 | Leave room for background jobs if they share the machine |
Then check memory. The budget is:
total ≈ master (cluster mode only) + workers × per-worker RSS after warm-up + other processes (jobs, Solid Queue in Puma) + headroom (≥ 20%)
As an example of the arithmetic (use your own Step 2 numbers): if a worker measures 300 MB after warm-up, the master 100 MB, and Solid Queue running inside Puma adds 150 MB, then 2 workers need about 100 + 2 × 300 + 150 = 850 MB, plus 20% headroom, about 1 GB. If the limit is 1 GB, two workers is the ceiling regardless of how many vCPUs you have; a second vCPU wouldn’t let you run a third worker.
# config/puma.rb
max_threads = ENV.fetch("RAILS_MAX_THREADS", 3).to_i
threads max_threads, max_threads
workers ENV.fetch("WEB_CONCURRENCY", 0).to_i # 0 on 1 vCPU, 2 on 2 vCPUs
preload_app! if ENV.fetch("WEB_CONCURRENCY", 0).to_i > 0
port ENV.fetch("PORT", 3000)
plugin :tmp_restart
plugin :solid_queue if ENV["SOLID_QUEUE_IN_PUMA"]
# Restart a worker if it exceeds this many MB (requires the puma_worker_killer gem),
# as a safety net while you investigate growth, not a fix:
# PumaWorkerKiller.config { |c| c.ram = 1024; c.percent_usage = 0.9 }
Keep pool in config/database.yml at least equal to RAILS_MAX_THREADS (plus Solid Queue’s threads if it runs in the same process); the connection pool sizing guide explains the math, and the Puma workers and threads guide goes deeper on the trade-offs.
Pro Tip: change one thing at a time and give it a full traffic cycle. Going from 1 to 2 vCPUs, from 0 to 2 workers and from 3 to 5 threads in one deploy makes it impossible to tell which change helped or which one caused the new memory pressure.
Verify it works
After a sizing change, rerun the same measurements at the same peak and compare:
bin/cpu-sample 300 # CPU used and throttling over 5 minutes at peak
cat /sys/fs/cgroup/memory.events # oom_kill must not have increased
curl -s "http://127.0.0.1:9293/stats?token=$PUMA_CONTROL_TOKEN" | grep -o '"backlog":[0-9]*'
And in the logs, compare p95 queue_time_ms and p95 duration for the same hour before and after. A successful CPU upgrade shows lower queue time and lower throttling with the same or lower p95 duration. If queue time didn’t change, the bottleneck wasn’t CPU.
For a controlled test, replay a realistic load against staging with each configuration; the staging environment guide covers setting one up that matches production’s allocation.
Troubleshooting
[3] ! Terminating timed out worker (Worker 1 failed to check in within 60 seconds): 41. A worker was stuck, often on CPU starvation (heavy throttling) or a request that never returned. Check throttling at that time and add a request timeout.
Killed in the logs with exit code 137, and oom_kill increased in memory.events. The container hit its memory limit. Reduce workers, investigate per-worker growth, or raise the limit.
ActiveRecord::ConnectionTimeoutError: could not obtain a connection from the pool within 5.000 seconds after adding threads. The database pool is smaller than the threads using it. Raise pool to match.
CPU shows 100% but cpu.max says max. There’s no quota, so you’re competing with other processes for the host. On a shared host, high CPU steal (st in top) means neighbours are using the core; a dedicated or higher-priority CPU allocation is the fix, not tuning.
Higher p95 after going from single mode to cluster mode on 1 vCPU. Two workers on one vCPU compete for the same core and add a master process. On 1 vCPU, single mode or one worker is usually faster.
How Heroku, Render, Fly.io and Railway size Rails apps
All four sell CPU and memory in fixed sizes or adjustable allocations; they differ in whether the CPU is shared, whether it can burst, and how easily you can resize.
| Platform | How CPU and memory are sized | Shared vs dedicated CPU | What you see when CPU-bound |
|---|---|---|---|
| Heroku | Dyno types pair memory with CPU share | Shared on Eco/Basic/Standard, dedicated on Performance dynos | Router H12 timeouts and rising queue time (X-Request-Start is set) |
| Render | Instance types pair CPU and RAM | Fractional CPU on small types, full CPUs on larger ones | Higher latency; metrics show CPU at the limit |
| Fly.io | Machine sizes: shared-cpu-* or performance-*, memory set separately |
Shared CPUs have a baseline quota with a burst balance | Throttling once the burst balance runs out |
| Railway | Usage-based, up to the plan’s per-service vCPU and RAM limit | Not documented | CPU graph per service and replica |
| Enkihost | Allocated shared vCPU and memory per app; allocations of 1.0 shared vCPU, or 2.0 vCPUs with CPU priority, with 1 GB of RAM per app | Shared, with CPU priority on the larger allocation | Throttling in cpu.stat, rising queue time |
Fly.io’s burst model deserves a note: a shared-CPU Machine can run well above its baseline for a while, then gets throttled to the baseline once its balance is spent. Load tests shorter than the burst window look great and say little about sustained peaks.
Author Perspective
My default answer to “do we need a bigger server?” is “show me queue time first”. Latency graphs make every slowdown look like a capacity problem, but slow responses with low CPU and near-zero queue time are almost always queries, N+1s or a slow external API, and more vCPUs don’t touch any of those. So my routine is the same three readings at a normal peak: CPU used against the quota, queue time, and per-worker memory after warm-up. If queue time is low, I leave the size alone and look at the code. If CPU is pinned and queue time climbs, a second vCPU with a second worker is one of the most predictable upgrades there is. The measurements take an afternoon; guessing is how apps end up paying for capacity they don’t use.
Sizing on Enkihost
On Enkihost, each Rails app runs with an allocated share of virtual CPU and memory, isolated from other apps, so the cgroup counters in this guide describe your app and nothing else.

- CPU allocations: 1.0 shared vCPU, or 2.0 vCPUs with CPU priority. With 1.0 vCPU, run Puma in single mode or one worker; with 2.0 vCPUs, two workers can use both.
- Memory is 1 GB per app on both allocations, so the memory budget in Step 5 is the ceiling on workers. Moving to 2 vCPUs gives the CPU for a second worker, but per-worker memory decides whether it fits.
- One process per app: background jobs run inside Puma (Solid Queue with
SOLID_QUEUE_IN_PUMA), so count their memory and CPU in the same budget. - Zero-downtime deploys let you change
WEB_CONCURRENCYandRAILS_MAX_THREADSand measure the result without a maintenance window. - Managed PostgreSQL and Redis run separately from the app’s allocation, so database work doesn’t consume the app’s CPU or memory.
See enkihost.com for details. For what to do after one app outgrows a single allocation, see how to scale a Rails app.
FAQ
How many Puma workers should I run on 1 vCPU?
Zero or one. On 1 vCPU, Puma’s single mode (no workers) with 3 to 5 threads avoids the master process’s memory and works well for most apps. One worker adds preload_app! and phased restarts. Two or more workers on one vCPU compete for the same core.
Does Rails use more than one CPU core?
One Ruby process runs Ruby code on one core at a time because of the GVL, although threads waiting on I/O release it. To use more than one core, run multiple processes: Puma workers in cluster mode, or a separate process for background jobs.
How do I know if my Rails app needs more memory?
Look for oom_kill above zero in /sys/fs/cgroup/memory.events, workers being killed with exit code 137, or memory.current staying close to memory.max. If memory grows steadily for days without levelling off, investigate a leak before adding memory.
Will 2 vCPUs make my Rails app twice as fast?
No. A second vCPU doesn’t make a single request faster; it lets two CPU-heavy requests run in parallel. It helps when requests queue because CPU is saturated, and has little effect when time is spent waiting on the database or external services.
What is CPU throttling in a container?
Throttling happens when a container uses its full CPU quota within a scheduling period and has to wait for the next one. It shows up as nr_throttled and throttled_usec in /sys/fs/cgroup/cpu.stat and causes latency spikes even when average CPU use looks moderate.
Sources
- Puma: clustered mode, workers and threads — Puma docs
- Puma: deployment and sizing — Puma docs
- Puma control/status app and stats — Puma docs
- Tuning Performance for Deployment — Rails Guides
- Control Group v2: cpu.max, cpu.stat, memory.events — Linux kernel docs
- Dyno types and sizes — Heroku Dev Center
- Request queue time and X-Request-Start — Heroku Dev Center
- Scaling — Render Docs
- CPU performance: shared vs performance CPUs, bursting — Fly Docs
- Scaling — Railway Docs