Heroku Labs: Disabling Keepalives to Dyno for Router 2.0
Last updated November 15, 2024
Table of Contents
For Common Runtime apps on Router 2.0, keepalives for all connections between the router and web dynos are enabled by default. To opt-out of keepalives to dynos, enable the Heroku Labs http-disable-keepalive-to-dyno
feature.
Features added through Heroku Labs are experimental and subject to change.
Overview
HTTP keepalive, also known as persistent connection, is a feature that allows a single TCP connection to remain open for multiple HTTP requests and responses, reducing the time and resources required for establishing new connections. With keepalives enabled, the router keeps the connection to the dyno open after each response, allowing subsequent requests to be sent over the same connection. This feature can improve the app’s efficiency and speed by minimizing the time spent on connection setups. However, in some cases, such as load-balancing optimizations or resource constraints, it can be preferable to disable keepalives.
Enabling the Heroku Labs feature disables keepalives to dynos, and each HTTP request is sent over a new connection.
Disable Keepalives for Apps on Router 2.0
To opt out of using keepalives to dynos, enable the Heroku Labs feature:
$ heroku labs:enable http-disable-keepalive-to-dyno -a <app name>
You can verify that your app is closing the connection by inspecting the HTTP headers sent to your dyno. You see a Connection: close
header in the request, indicating that the connection will close after the response.
Enable Keepalives for Apps on Router 2.0
To re-enable keepalives, disable the Heroku Labs feature:
$ heroku labs:disable http-disable-keepalive-to-dyno -a <app name>
After disabling, the router maintains persistent connections, and the Connection: close
header no longer appears in the request headers sent to your app, allowing subsequent requests to reuse the open connection.