问题:
var httpclient = _httpClientFactory.CreateClient();
var url = "https://www.baidu.com/";
var rlt = await httpclient.PostAsync(url, new JsonContent(new { a = 1, b = 2 }));
var bts = await rlt.Content.ReadAsByteArrayAsync();
就是简单的post 百度网址 压测1000并发 单节点服务器
查看日志 有一部分出现
PostJson Error>>The operation was canceled. at System.Net.Http.HttpConnection.ContentLengthReadStream.CompleteCopyToAsync(Task copyTask, CancellationToken cancellationToken)
at System.Net.Http.HttpConnection.HttpConnectionResponseContent.SerializeToStreamAsync(Stream stream, TransportContext context, CancellationToken cancellationToken)
at System.Net.Http.HttpContent.LoadIntoBufferAsyncCore(Task serializeToStreamTask, MemoryStream tempBuffer)
at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
压测报告上平均响应时间快三秒 想问各位大佬是什么原因
回答1:
可以看看之前的相关博问:在.NET中你们是如何捕捉 HttpClient中的超时错误的
回答2:
在压测的时候,看看你本地的TCP连接到达了多少。
回答3:
后续发现百度自身也不是每次都是有效response 换了同机房的接口测试 无异常