HttpRequest.setConnectionCacheSize

Changes the limit of number of open, inactive sockets. Reusing connections can provide a significant performance improvement, but the operating system can also impose a global limit on the number of open sockets and/or files that you don't want to run into. This lets you choose a balance right for you.

More...
class HttpRequest
version(arsd_http_internal_implementation)
static
void
setConnectionCacheSize
(
int max = 32
)

Detailed Description

When the total number of cached, inactive sockets approaches this maximum, it will check for ones closed by the server first. If there are none already closed by the server, it will select sockets at random from its connection cache and close them to make room for the new ones.

Please note:

  • there is always a limit of six open sockets per domain, per the common practice suggested by the http standard
  • the limit given here is thread-local. If you run multiple http clients/requests from multiple threads, don't set this too high or you might bump into the global limit from the OS.
  • setting this too low can waste connections because the server might close them, but they will never be garbage collected since my current implementation won't check for dead connections except when it thinks it is running close to the limit.

Setting it just right for your use case may provide an up to 10x performance boost.

This implementation is subject to change. If it does, I'll document it, but may not bump the version number.

Meta

History

Added August 10, 2022 (dub v10.9)