Measuring cpu time for http request in async controller


This Content is from Stack Overflow. Question asked by skyde

I was reading google SRE book chapter on handling overload :

They mention:

An interesting part of the puzzle is computing in real time the amount of resources—specifically CPU—consumed by each individual request. This computation is particularly tricky for servers that don’t implement a thread-per-request model, where a pool of threads just executes different parts of all requests as they come in, using nonblocking APIs.

I know in a thread-per-request model, we could simply call getrusage(RUSAGE_THREAD, &r);
but in a Controller with async methods it’s not guaranteed that code before and after the “await” keyword will execute on the same thread.
and even if it does, it’s possible the thread also executed code for other http request.

So is there a way to measure how much cpu time an async function used.


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?