ChrisBellew
ChrisBellew

Reputation: 1174

Is there a way to get the time spent in request queue in Kestrel/ASP.NET Core?

My understanding is that ASP.NET Core middleware is run when a request is ready to be processed. But if the app is under load and ASP.NET Core can not process all the requests as they come in, they are put in a "queue" somewhere? I don't know whether this is some managed queue inside Kestrel or whether it has something to do with libuv.

I would like to be able to know how long a given request is spent in this queue. Is there something on HttpContext that can tell me this?

Thanks in advance

Upvotes: 18

Views: 3348

Answers (1)

Dexion
Dexion

Reputation: 1101

This question is not that easy.

If you want to track all of the times, you have to do a lots of steps. At the beginning add a unique stamp or the ticks to the requests, so you can identify them one by one. Second, create a handler, which intercepts your requests and logs the times. Third, add a logging point to every request related method. Fourth - this will be a surprise - you can't do anything big to reduce this time expect the configuration of IIS regarding threading, parallel requests, session handling, etc. Fifth - if your browser measures 2000 ms, your server measures 200 ms, it's not the .NET core, its your code/architecture/config. Sorry to tell you bad news.

Use the System.Diagnostics.Stopwatch class to measure the time.

Upvotes: 4

Related Questions