Skip to content

Enable HTTP connection reuse (keep-alive) in Hlquery::Client to eliminate per-request TCP/TLS overhead #4

Description

@cferrys

Summary

Hlquery::Client currently creates an LWP::UserAgent without a connection cache, which can force new TCP/TLS handshakes per request. Add keep-alive connection reuse (and lightweight configurability) to significantly reduce latency and CPU overhead for high-throughput hlquery workloads.

Context

hlquery is designed for high-performance search; the Perl client is expected to issue many small HTTP requests (health/stats, document CRUD, search, SAM, SQL). In lib/Hlquery/Client.pm, new() constructs LWP::UserAgent->new(...) but does not configure conn_cache, so connection pooling/keep-alive reuse is not guaranteed. This is especially costly for:

  • bulk indexing loops (Documents->Add/Update/Delete)
  • search-heavy traffic (Search, MultiSearch, SAM->Search, SQL->Query/Search)
  • TLS deployments (handshake cost dominates)

Proposed Implementation

  • Update lib/Hlquery/Client.pm new() to enable connection reuse by default:
    • Add use LWP::ConnCache;
    • Configure LWP::UserAgent->new(..., keep_alive => 1, conn_cache => LWP::ConnCache->new())
  • Add minimal options passthrough (backwards compatible):
    • keep_alive (default: enabled)
    • conn_cache_size (default: reasonable small value, e.g. 10–50)
  • Add a short benchmark/example script under examples/ that compares repeated Health()/Search() calls with and without keep-alive (measure wall time).
  • Document the new options in README.md (keep it focused on performance + production defaults).

Impact

  • Lower p50/p95 latency for typical hlquery request patterns (especially under TLS).
  • Reduced CPU usage and fewer ephemeral ports/socket churn on clients.
  • Higher sustainable QPS from the same application instance with no API changes for existing users.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions