Skip to content

The TCP connection pool reuse #1461

Closed
Closed
@yilezhu

Description

@yilezhu

When I test restsharp for requests, I find that there are many TCP connections established. Can these TCP connections be reused? If I have too many requests, the established TCP connection will occupy all my local ports and eventually cause my program to crash!
The test code :

 var client = new RestClient("https://www.cnblogs.com/yilezhu/p/12830123.html");
            var request = new RestRequest();
            var response = client.Get(request);
            Console.WriteLine("100个请求测试开始~~~~" + DateTime.Now);
            Stopwatch stopwatch = Stopwatch.StartNew();
            await Task.WhenAll(Enumerable.Range(0, 100)
               .Select(_ => Task.Run(() =>
             {
                 var response = client.Get(request);
             }))).ConfigureAwait(false);
            stopwatch.Stop();

            Console.WriteLine("100个请求测试结束~~~~" + DateTime.Now);
            Console.WriteLine("总共用时" + stopwatch.ElapsedMilliseconds / 1000 / 60 + "分钟");

The TCP connections I see through tcpview are as follows:
image
Expect answers and Solutions。Thanks!!!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions