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.
Summary
Hlquery::Clientcurrently creates anLWP::UserAgentwithout 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()constructsLWP::UserAgent->new(...)but does not configureconn_cache, so connection pooling/keep-alive reuse is not guaranteed. This is especially costly for:Documents->Add/Update/Delete)Search,MultiSearch,SAM->Search,SQL->Query/Search)Proposed Implementation
lib/Hlquery/Client.pmnew()to enable connection reuse by default:use LWP::ConnCache;LWP::UserAgent->new(..., keep_alive => 1, conn_cache => LWP::ConnCache->new())keep_alive(default: enabled)conn_cache_size(default: reasonable small value, e.g. 10–50)examples/that compares repeatedHealth()/Search()calls with and without keep-alive (measure wall time).README.md(keep it focused on performance + production defaults).Impact