client, err := stream.NewClient(apiKey, apiSecret,
stream.WithMaxConnsPerHost(20),
stream.WithIdleTimeout(55*time.Second),
stream.WithConnectTimeout(5*time.Second),
stream.WithRequestTimeout(20*time.Second),
)Connection Pooling
Every backend SDK ships with HTTP connection pooling configured by default. The SDK emits one INFO-level log on client construction listing the effective values so you can verify your configuration.
Defaults
| Setting | Default | What it does |
|---|---|---|
| Max connections per host | 5 | Upper bound on concurrent TCP connections to a single host. |
| Idle timeout | 55 s | Closes a connection that has been idle for this duration. |
| Connect timeout | 10 s | Caps the TCP + TLS handshake. |
| Request timeout | 30 s | Default per-call deadline from request send to full response. Override per call. |
| Keep-alive | always on | HTTP persistent connection reuse. Not user-tunable. |
Tune the knobs
Pass the four knobs at client construction.
var client = new StreamClient(new StreamOptions
{
ApiKey = apiKey,
ApiSecret = apiSecret,
MaxConnsPerHost = 20,
IdleTimeout = TimeSpan.FromSeconds(55),
ConnectTimeout = TimeSpan.FromSeconds(5),
RequestTimeout = TimeSpan.FromSeconds(20),
});Per-call request timeout
Override the request timeout for a single call without rebuilding the client.
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));
var app = await client.GetAppAsync(cts.Token);Bring your own HTTP client
When you pass a pre-built HTTP client, the SDK uses it as-is and applies none of the four knobs above. You own all transport behavior, including timeouts, retries, and response decompression.
var client = new StreamClient(new StreamOptions
{
ApiKey = apiKey,
ApiSecret = apiSecret,
HttpClient = myHttpClient,
});SDK-specific notes
- PHP:
maxConnsPerHostandidleTimeoutare enforced via libcurl's persistent multi-handle pool (CURLMOPT_MAX_HOST_CONNECTIONSandCURLOPT_MAXLIFETIME_CONN). They take effect only when the SDK client is reused across requests within a single PHP process: long-running runtimes such as Swoole, RoadRunner, ReactPHP, and CLI daemons. Instantiate the SDK client once and reuse it. Under PHP-FPM (and one-shot CLI scripts) the PHP process exits at the end of each request, so there is no cross-request pool to size; the per-call request and connect timeouts still apply.idleTimeoutrequires libcurl 7.80.0 (Nov 2021) or later. - Ruby: pooling relies on the
net_http_persistentFaraday adapter. If a customfaraday_adapter:you pass cannot be configured, the SDK logs a warning and falls back to Faraday's default (non-pooling) adapter; the INFO log on construction reports the effective adapter. - Java: the environment variables
STREAM_API_TIMEOUTandSTREAM_API_CONNECTION_MAX_AGE(and their system-property equivalentsio.getstream.timeoutandio.getstream.connection.maxAge) still take effect and are folded into the default options. - .NET: on the escape-hatch path the SDK does not configure gzip decompression on your handler. Enable
AutomaticDecompression = DecompressionMethods.GZipon your ownSocketsHttpHandlerif you need it.