我面临着Kestrel服务器性能的问题.我有以下情况:
I'm facing problem with kestrel server's performance. I have following scenario :
TestClient(JMeter) -> DemoAPI-1(Kestrel) -> DemoAPI-2(IIS)我正在尝试创建一个示例应用程序,该应用程序可以在请求时获取文件内容.TestClient(100个线程)向DemoAPI-1请求,而后者又向DemoAPI-2请求.DemoAPI-2读取一个固定的XML文件(最大1 MB)并返回其内容作为响应(在生产中,DemoAPI-2不会暴露给外界).
I'm trying to create a sample application that could get the file content as and when requested. TestClient(100 Threads) requests to DemoAPI-1 which in turn request to DemoAPI-2. DemoAPI-2 reads a fixed XML file(1 MB max) and returns it's content as a response(In production DemoAPI-2 is not going to be exposed to outside world).
当我测试了从TestClient-> DemoAPI-2的直接访问时,得到了以下预期结果(好):
When I tested direct access from TestClient -> DemoAPI-2 I got expected result(good) which is following :
但是当我尝试通过DemoAPI-1访问它时,得到了以下结果:
But when I tried to access it through DemoAPI-1 I got following result :
如您所见,两者之间存在巨大差异.我什至没有获得10%的DemoAPI-2吞吐量.我被告知,与传统的IIS相比,茶est具有更高的效率和速度.另外,由于直接访问没有问题,我认为我们可以消除在DemoAPI-2上出现问题的可能性.
As you can see there is a huge difference.I'm not getting even the 10% throughput of DemoAPI-2. I was told has kestrel is more efficient and fast compared to traditional IIS. Also because there is no problem in direct access, I think we can eliminate the possible of problem on DemoAPI-2.
※DemoAPI-1的代码:
※Code of DemoAPI-1 :
string base64Encoded = null; var request = new HttpRequestMessage(HttpMethod.Get, url); var response = await this.httpClient.SendAsync(request, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false); if (response.StatusCode.Equals(HttpStatusCode.OK)) { var content = await response.Content.ReadAsByteArrayAsync().ConfigureAwait(false); base64Encoded = Convert.ToBase64String(content); } return base64Encoded;※DemoAPI-2的代码:
※Code of DemoAPI-2 :
[HttpGet("Demo2")] public async Task<IActionResult> Demo2Async(int wait) { try { if (wait > 0) { await Task.Delay(wait); } var path = Path.Combine(Directory.GetCurrentDirectory(), "test.xml"); var file = System.IO.File.ReadAllText(path); return Content(file); } catch (System.Exception ex) { return StatusCode(500, ex.Message); } }一些其他信息:
该问题归因于HttpClient的端口耗尽问题.我能够通过使用IHttpClientFactory解决此问题.下一篇文章可能会帮助遇到类似问题的人.
The problem was due to HttpClient's port exhaustion issue. I was able to solve this problem by using IHttpClientFactory. Following article might help someone who faces similar problem.
www.stevejgordon.co.uk/httpclient-creation-and-disposal-internals-should-i-dispose-of-httpclient
更多推荐
ASP.NET Core 2.2 Kestrel服务器的性能问题
发布评论