Closed
Description
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:
Expect answers and Solutions。Thanks!!!