【发布时间】:2014-02-22 05:20:49
【问题描述】:
我使用 RestSharp 作为底层 HTTP 客户端库,在黑盒服务上创建压力/吞吐量测试客户端。 Threadpool 和 Servicepoint 连接限制已提升到 5000,但这不应该太担心,因为我们正在测试每秒大约 500-1000 个请求。高分辨率(微秒)计时器组件用于以我们想要测试的速率抛出请求。
RestSharp 代码大致是这样的
restClient.ExecuteAsync(postRequest, res =>
{
stopwatch.Stop();
lock (this.countLocker)
{
this.roundTrips.Add(stopwatch.ElapsedMilliseconds);
if (res.ResponseStatus == ResponseStatus.Completed &&
(res.StatusCode == HttpStatusCode.OK ||
res.StatusCode == HttpStatusCode.NoContent))
{
this.responseCount++;
}
else
{
// Treat all other status codes as errors.
this.reportError(res);
}
}
});
在发送过多请求时,我们会观察到服务会在一段时间后溢出一些错误 503 响应,但 RestSharp 将这些响应视为完整响应,因为这是来自服务器的有效响应;没有抛出任何实际异常。
不清楚的是RestSharp何时因底层连接错误而遇到异常
The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.
at RestSharp.Http.GetRawResponseAsync(IAsyncResult result, Action`1 callback)
at RestSharp.Http.ResponseCallback(IAsyncResult result, Action`1 callback)
或
The underlying connection was closed: An unexpected error occurred on a receive.
at RestSharp.Http.GetRawResponseAsync(IAsyncResult result, Action`1 callback)
at RestSharp.Http.ResponseCallback(IAsyncResult result, Action`1 callback)
这似乎表明 RestSharp 正在使用 HTTP keep-alive 进行连接。有没有办法控制这种行为?我似乎找不到任何设置来指示 RestSharp不使用 keep-alive。
除此之外,我还试图更好地了解如何进一步调查服务器中断这些连接的实际问题?仅仅是客户端发出的连接数超过了服务器可以处理的问题吗? (因为它跟不上它的响应速度)
【问题讨论】:
标签: restsharp keep-alive throughput