Heroku Labs: Disabling Keepalives to Dyno for Router 2.0
Last updated November 11, 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 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 might be preferable to disable keepalives.
By enabling the Heroku Labs feature below, keepalives to dynos will be disabled, and each HTTP request will be sent over a new connection.
Disable Keepalives for Apps on Router 2.0
To opt out of using keepalives to dynos, enable the 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 should see a Connection: close
header in the request, indicating that the connection will be closed after the response.
Enable Keepalives for Apps on Router 2.0
To re-enable keepalives, disable the Labs feature with the following command:
$ heroku labs:disable http-disable-keepalive-to-dyno -a <app name>
Once disabled, the router should maintain persistent connections, and the Connection: close
header will no longer appear in the request headers sent to your app, allowing subsequent requests to reuse the open connection.