Kestrel is not allowing async so requests are being blocked
My server will ONLY handle one request at a time.
I am testing an ASP.NET Core Web Application using MVC and WebApi and Kestrel Web Server.
var host = new WebHostBuilder()
.UseKestrel(opt => opt.ThreadCount = 10)
.UseConfiguration(config)
.UseContentRoot(path)
.UseStartup<Startup>()
.Build();
For some reason when the server is processing a request it will not accept in any new requests. From what I have read this should not be the case but I cannot figure out what I am doing wrong.
Here is my WebApi controller code:
[HttpPost]
[Route("/api/test/{moduleid}")]
public Task<object> Api(string moduleId, [FromBody] JObject data)
{
return Task.Run( () =>
{
return domain.Handle(moduleId, data);
});
}
The code is not Async so I am wrapping in a Task.Run call. Everything works but the server blocks new requests until the current request finishes.
Kestrel can handle many simultaneous connections/requests. You don't need to change opt.ThreadCount or call Task.Run. While blocking in a controller action is worse performance-wise than doing async IO, the controller action is already dispatched to the threadpool, so the Task.Run is redundant.
What makes you think that Kestrel can only process one request at a time? The way I see it, there are two likely possibilities. domain.Handle(moduleId, data) takes a lock or something effectively blocking new calls until the previous calls finish, or the client your using is using a single TCP connection and is queuing up requests one-after-the-other that you think should be made parallel.
You can figure out which of these is the case by testing with Fiddler/Message Analyzer/Wireshark and by logging immediately before and after the call to domain.Handle(moduleId, data).
Must be my client. I place breakpoints in my controller and can tell when requests are coming through. I am using postman to test and I bet postman is blocking even though I opened multiple postman windows. I'll test with another tool as well.
I only added task.run to try to resolve the issue I was experiencing.
Rex Bloom Applications Director, Kalos, inc. 800-264-0068
use 785-220-8025 for texting or urgent requests.
On May 23, 2017, at 4:37 PM, Stephen Halter <[email protected]mailto:[email protected]> wrote:
Kestrel can handle many simultaneous connections/requests. You don't need to change opt.ThreadCount or call Task.Run. While blocking in a controller action is worse performance-wise than doing async IO, the controller action is already dispatched to the threadpool, so the Task.Run is redundant.
What makes you think that Kestrel can only process one request at a time? The way I see it, there are two likely possibilities. domain.Handle(moduleId, data) takes a lock or something effectively blocking new calls until the previous calls finish, or the client your using is using a single TCP connection and is queuing up requests one-after-the-other that you think should be made parallel.
You can figure out which of these is the case by testing with Fiddler/Message Analyzer/Wireshark and by logging immediately before and after the call to domain.Handle(moduleId, data).
You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/aspnet/KestrelHttpServer/issues/1852#issuecomment-303539464, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AFBUR6_2xO32OainJErZKjKwQy6Vv5_Vks5r81FogaJpZM4NkTcz.
ok, so it was postman. so strange.
Glad you figured it out.