Skip to content
Tutorials Center
My learning

Topics

Lesson 26 of 37 ยท Scaling and Performance

Router Metrics and Request Timeouts

Read Heroku router log lines, understand connect and service time, the 30 second request timeout (H12), memory errors R14 and R15, and what the Metrics tab shows.

Heroku's router is the front door of every app. It receives each HTTPS request, picks a web dyno and forwards the request. Because it sees every request, it also writes a log line for each one, and those lines are the best performance data you get for free. This lesson teaches you to read them, explains the timeouts, and shows the Metrics tab signals. Real logs cannot be fetched on this site, so the sample lines below are invented for teaching and the parser is a runnable stand-in.

Anatomy of a router log line

A line in heroku logs --tail looks like this (an invented example, split over lines for reading):

TEXT
at=info method=GET path="/products" host=example.com request_id=8601b555-6a83-4c12-8269-97c8e32cdb22
fwd="203.0.113.7" dyno=web.1 connect=1ms service=34ms status=200 bytes=1450 protocol=https

The fields:

  • at: the level; info for normal requests, error when the router itself failed (timeouts and crashes).
  • method, path, host: the request.
  • request_id: a unique id you can also pass on in your own logs to join lines together.
  • dyno: which dyno served the request.
  • connect: time the router needed to open a connection to the dyno. High numbers mean the dyno was overloaded or booting.
  • service: time between the router sending the request and the dyno finishing its response. This is your app's processing time.
  • status: the HTTP status; bytes: the response size.
  • code=H12 style fields appear on errors.

Parsing logs

The log format (called logfmt) is key=value pairs, with quotes around values containing spaces. Parsing it is a good way to find the slowest routes.

Python Stand-in: parse router lines and find slow paths

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The slowest line is the 30-second report, which carries code=H12; the 2.2 second checkout is the next candidate to improve.

The 30 second rule

The router waits at most 30 seconds for a dyno to start sending a response. After that it returns an error page with code H12 (Request timeout) and status 503. The app may keep working on the request, but nobody is listening any more. The fix is never "raise the timeout" (you cannot); it is to make the request faster or move the work to a background worker and tell the user the work is queued.

Other common router codes:

Code Meaning Usual cause
H10 App crashed Process exited; look at the logs before the request
H12 Request timeout Handler took over 30 s
H13 Connection closed without response Dyno killed the connection (crash or restart)
H14 No web dynos running web scaled to 0 or no Procfile web process
H18 Server request interrupted Dyno closed the socket mid-response
H20 App boot timeout Dyno did not bind its port in time

Boot problems have the R10 code (boot timeout: the process did not bind to $PORT within 60 seconds). The full list is in the Dev Center, and troubleshooting walks through common cases.

Memory errors

Heroku measures dyno memory, not just the app heap. At the quota you see R14 (Memory quota exceeded): the dyno starts using swap, which slows everything down. At about twice the quota you see R15 (Memory quota vastly exceeded) and the dyno is killed. Typical causes are loading entire large files or query results into memory, unbounded caches inside the process, and too many worker processes for the dyno size.

Python Stand-in: memory budget per worker

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

You get 2, 5 and 14 workers (using example memory numbers). Reserve some headroom; memory grows as requests of different sizes arrive. Setting the worker count from an environment variable (such as WEB_CONCURRENCY) lets you change it without a code change.

The Metrics tab

In the dashboard, an app's Metrics tab charts the same signals without any parsing: response time (median, 95th, 99th percentile), throughput, memory use, dyno load and error counts (H/R codes) per dyno type. Read it like this:

  1. Look at p95/p99, not the average; slow outliers are the user complaints.
  2. Compare throughput against response time: if both rise, you need capacity; if only time rises, something got slower.
  3. Check memory for a staircase that never comes back down (a leak).
  4. Correlate spikes with your deploy times (the Activity tab).

Heroku can also add runtime metrics to your logs (heroku labs:enable log-runtime-metrics), so a log drain tool can chart them, see logging.

flowchart LR
    B["Browser"] -->|"HTTPS"| R["Router<br/>logs every request"]
    R -->|"connect"| D["Dyno"]
    D -->|"service"| R
    R -->|"30 s without answer"| E["H12 error page"]

The router measures connect and service time and gives up after 30 seconds.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does the service field in a router log line measure?

    service is the dyno's processing time as seen by the router; connect is the time to open the connection.
  2. 2. What happens when a dyno takes longer than 30 seconds to start responding?

    The router gives up at 30 seconds and shows H12; the timeout cannot be raised.
  3. 3. Which code means a process did not bind to the port within 60 seconds?

    R10 is the boot timeout; H20 is the router-side equivalent for the web dyno.
  4. 4. R14 means what?

    R14 warns that the dyno exceeded its memory quota; R15 means it is far over and gets killed.

Summary

  • Router logs give connect, service, status and dyno for every request.
  • The router gives up after 30 seconds (H12); move slow work to workers.
  • R14 and R15 are memory errors; size workers to the dyno.
  • Use the Metrics tab for p95/p99, throughput, memory and error counts.

Next: Pipelines and Promotion