Skip to content

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

What to watch

SignalWhereWorry when
Action p95 and errorsTracesAbove target
Puma backlog / pool capacityPuma statsBacklog above zero for minutes
ActiveRecord time per requestTracesMost of the request time
Sidekiq latency per queueSidekiq APIOldest job waiting longer than your SLA
Worker RSSProcess metricsGrows until killed

Puma stats

ruby
# 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") }
bash
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, preload or eager_load; the Bullet gem catches them in development.
  • Puma threads waiting on the database pool: pool in database.yml should be at least the Puma thread count.
  • Memory bloat from large result sets loaded into memory; use find_each and 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.

What to watch in Ruby applications

SignalSourceWhy
Latency per controller actionOpenTelemetry tracesFind the slow actions
Puma busy threads and backlogPuma stats (pumactl stats)A full thread pool queues requests
Database time and query count per requestActiveRecord spansN+1 queries are the most common Rails slowdown
Background jobsSidekiq queue latency, retries, dead setJobs that pile up or fail silently
Memory per workerProcess RSSRuby processes grow; find leaks before restarts hide them
GC timeGC.statHeavy 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.

Frequently asked questions

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

  • 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.