Keep connections warm and cheap

Network setup can cost 60–120 ms.
Reuse connections and cut TLS work.

Java 17 HttpClient:

var client = HttpClient.newBuilder()
    .version(HttpClient.Version.HTTP_2) // multiplex, fewer sockets
    .connectTimeout(Duration.ofMillis(200))
    .followRedirects(HttpClient.Redirect.NEVER)
    .sslParameters(new SSLParameters()) // allow session resumption
    .build();

// Example call; reuse client across requests
var req = HttpRequest.newBuilder(URI.create("https://api.internal/users/42"))
    .header("Connection", "keep-alive")
    .GET().build();
var res = client.send(req, HttpResponse.BodyHandlers.ofString());




HTTP/2 with keep-alive and TLS session resumption trimmed ~40–70 ms on coldish paths and stabilized p95.

Alternative: If the client sits behind a gateway, enable connection pools there and pin upstream IPs to tame DNS variance.



참고 - 상세 링크

+ Recent posts