Skip to content

Proxy server opens a new outbound TCP/HTTP connection per request (no reuse) #117

@ameba23

Description

@ameba23

This is a performance issue and a proposal to enhance performance / throughput.

Problem

ProxyServer::handle_http_request opens a fresh TcpStream::connect and performs a new Hyper HTTP/1.1 client handshake for every incoming request. This disables keep‑alive reuse and adds per‑request connection overhead (DNS resolution, TCP handshake, HTTP handshake).

  • File: src/lib.rs
  • Function: ProxyServer::handle_http_request

Impact

  • Throughput is limited by connection setup rather than request handling.
  • Higher latency under load.
  • Increased CPU usage and ephemeral port churn.

Proposed fix

Introduce outbound connection reuse:

  • Maintain a persistent HTTP client connection to the target service.
  • Prefer HTTP/2 upstream when available to multiplex requests.
  • Avoid TcpStream::connect per request.

Acceptance criteria

  • Outbound connections are reused across multiple requests (observable via logs).
  • Nice to have: throughput improves in a load test vs. current baseline.
  • No regression in proxy correctness (headers, attestation metadata, error handling).

Notes

The current code creates the outbound connection here:

  • src/lib.rsProxyServer::handle_http_request (TcpStream::connect, http1::Builder::handshake).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions