Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MaximKojineMojio opened this issue Nov 25, 2019 · 3 comments

Comments

@MaximKojineMojio
Copy link

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);
            }
        }
    }
@zivillian
Copy link
Contributor

Have you tried increasing the GraphiteClient.BatchSize? Maybe you should add some kind of aggregator like StatsD .

@MaximKojineMojio
Copy link
Author

We did.... And it didn't help. But it might not help because we didn't increase it enough.
We are going to apply a few adjustments

  1. Adjust the TcpTimedWaitDelay setting
    https://docs.microsoft.com/en-us/biztalk/technical-guides/settings-that-can-be-modified-to-improve-network-performance
  2. Increase BatchSize and decrease Flush Period

@zivillian
Copy link
Contributor

I've implemented a first version of connection pooling 3ab559d
Please let me know, if this would solve your problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants