[HTTP2] Feat: add H2 probing option for faster health checks - #2485
[HTTP2] Feat: add H2 probing option for faster health checks#2485pulkit4tech wants to merge 2 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2485 +/- ##
==========================================
- Coverage 85.23% 85.22% -0.01%
==========================================
Files 281 281
Lines 16773 16797 +24
==========================================
+ Hits 14296 14315 +19
- Misses 2015 2018 +3
- Partials 462 464 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| if conn != nil { | ||
| conn.Close() | ||
| var err error | ||
| if p.transport.useH2Probe { |
There was a problem hiding this comment.
Does this still work for http1 connections when the destination doesn't accept http2?
Actually, http1 outbounds will have to open new connections just for the probing.
Can we make it an outbound config rather than transport?
| ctx, cancel := context.WithTimeout(context.Background(), p.transport.connTimeout) | ||
| defer cancel() | ||
|
|
||
| req, err := http.NewRequestWithContext(ctx, http.MethodHead, "http://"+p.addr, nil) |
There was a problem hiding this comment.
How can we deal with destinations that require https?
| }, | ||
| DisableCompression: options.disableCompression, | ||
| IdleConnTimeout: options.idleConnTimeout, | ||
| PingTimeout: defaultHTTP2PingTimeout, |
There was a problem hiding this comment.
Http2 is already probing (afaik every 20s) to keep the connections alive, so we don't need to probe to detect Active->Unhealthy.
We only need active probing to detect when unhealthy peers are back to active.
Problem
The HTTP transport's peer health-check loop (
MaintainConn→isAvailable)probes peer availability by opening a new TCP connection on every check
and immediately closing it. This pays the full TCP handshake cost each time
(~1.6 ms measured). For deployments with short innocence windows or large
peer pools, this overhead accumulates on the connection-management goroutines.
Solution
Add an opt-in
H2Probing()TransportOption. When set,isAvailable()issuesa zero-body
HEADrequest through the existingh2Transportconnection poolinstead of dialing a new TCP socket. After the first connection is established,
subsequent probes reuse the pooled connection, reducing probe latency by ~8.4×.
The original TCP dial path is preserved as the default — no behaviour change for
existing callers.
Usage
RELEASE NOTES: Add H2Probing() TransportOption to reduce peer health-check latency by 8× by reusing the HTTP/2 connection pool instead of dialing a new TCP connection per probe.