Performance monitoring
Ruby and Rails performance monitoring
Rails apps slow down from N+1 queries, saturated Puma workers and memory bloat. Traces per controller action show which, and Sidekiq needs its own watch.
3 min read10 sectionsUpdated
On this page
| Signal | Where | Worry when |
|---|---|---|
| Action p95 and errors | Traces | Above target |
| Puma backlog / pool capacity | Puma stats | Backlog above zero for minutes |
| ActiveRecord time per request | Traces | Most of the request time |
| Sidekiq latency per queue | Sidekiq API | Oldest job waiting longer than your SLA |
| Worker RSS | Process metrics | Grows until killed |
# config/puma.rb: enable the control app (bind to localhost)
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":4,"worker_status":[{"last_status":{"backlog":0,"running":5,"pool_capacity":2,"max_threads":5}}, ...]}Typical Rails bottlenecks
- N+1 queries: use
includes,preloadoreager_load; the Bullet gem catches them in development. - Puma threads waiting on the database pool:
poolin database.yml should be at least the Puma thread count. - Memory bloat from large result sets loaded into memory; use
find_eachand pluck. - Slow views rendering many partials; fragment caching helps.
- Sidekiq jobs that call slow APIs without timeouts, starving queues.
Tracing
Three gems and an initializer instrument Rails, ActiveRecord, Net::HTTP, Redis and Sidekiq; see OpenTelemetry for Rails. For CPU profiles, stackprof or rbspy produce a flame graph without code changes.
| Signal | Source | Why |
|---|---|---|
| Latency per controller action | OpenTelemetry traces | Find the slow actions |
| Puma busy threads and backlog | Puma stats (pumactl stats) | A full thread pool queues requests |
| Database time and query count per request | ActiveRecord spans | N+1 queries are the most common Rails slowdown |
| Background jobs | Sidekiq queue latency, retries, dead set | Jobs that pile up or fail silently |
| Memory per worker | Process RSS | Ruby processes grow; find leaks before restarts hide them |
| GC time | GC.stat | Heavy allocation shows as GC pauses |
Instrumenting Rails
Install the OpenTelemetry Ruby SDK with the Rails, ActiveRecord, Net::HTTP and Sidekiq instrumentations; see OpenTelemetry for Rails. Measure Sidekiq queue latency (how long the oldest job has waited), not only queue size: a queue of ten that never moves is worse than a busy queue of a thousand.
How many Puma workers and threads?
Workers roughly equal to CPU cores, and a few threads each (often 3 to 5). Measure backlog and latency, and keep the database pool at least as large as the thread count.
Does YJIT help?
For many Rails apps it reduces CPU time noticeably. Enable it in staging, compare latency and memory, then roll out.
Check it now, free
- Response time checker: Measure TTFB with DNS, connect, TLS and server time.
Related reading
- OpenTelemetry for Flask: Instrument a Flask app with OpenTelemetry, in code or with zero code: trace routes, SQLAlchemy and outgoing calls, and export to VitalRix.
- Go performance monitoring: Monitor Go services: goroutine counts, GC and heap, request latency per handler, pprof profiling in production and OpenTelemetry tracing with otelhttp.
- PHP performance monitoring: Monitor PHP and Laravel apps: request latency, PHP-FPM worker saturation, OPcache hit rate, slow queries, external calls and errors.
- Python performance monitoring: Monitor Python web apps: request latency per route, worker saturation, the GIL and CPU-bound code, database time, Celery queues and memory.
- OpenTelemetry for Django: Trace a Django app with OpenTelemetry: auto-instrument views and the ORM, run under gunicorn safely, trace Celery tasks and export to VitalRix.
- Java performance monitoring: Monitor Java and Spring applications: JVM heap and GC, thread pools, JDBC connection pools, request latency from traces.
Watch your own site and services with VitalRix
Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.