Skip to content

Allow to pass HttpClient Factory and custom TcpClient Factory to GraphiteClient in order to avoid exhausting the connection pool #23

@MaximKojineMojio

Description

@MaximKojineMojio

Assume you have an SF application with 20 microservices running on the same node.
And each of these microservice writes 1000 datapoints every 2 seconds. Windows OS has default setting [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\ Services\Tcpip\ Parameters\ TcpTimedWaitDelay] 240 seconds. Eventually, you will experience TCP port exhaustion.

    private async Task SendInternalAsync(ICollection<Datapoint> datapoints, CancellationToken cancellationToken)
    {
        TcpClient client;
        if (UseDualStack)
        {
            **client = new TcpClient(AddressFamily.InterNetworkV6) {Client = {DualMode = true}};**
        }
        else
        {
            **client = new TcpClient();**
        }
        using (client)
        {
            await client.ConnectAsync(Host, Formatter.Port).ConfigureAwait(false);
            cancellationToken.ThrowIfCancellationRequested();
            using (var stream = client.GetStream())
            {
                await Formatter.WriteAsync(stream, datapoints, cancellationToken).ConfigureAwait(false);
            }
        }
    }

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