It is expected for response time to be less than the total time spent in async-await usage scenerios. Consider the following code example for a web endpoint:
async Task<string> WebEndpointExample()
await DoSomethingForSomeSecondsAsync(5);
[MethodImpl(MethodImplOptions.NoInlining)]
private static async Task DoSomethingForSomeSecondsAsync(int seconds)
await Task.Delay(TimeSpan.FromSeconds(seconds));
In this code example, it takes approximately 5 seconds for the WebEndpointExample to complete, so the response time for the transaction that represents the request to the WebEndpointExample endpoint will be approximately 5 seconds.
The agent also captures the "busy" time (the time that the instrumented method is actually executing) of each individual segment that constitutes the transaction. They are WebEndpointExample and DoSomethingForSomeSecondsAsync. Ideally, the total execution time of the two segments is equal to the response time (approximately 5 seconds).
It is easy to see that the execution time of DoSomethingForSomeSecondsAsync is 5 seconds. However, the execution time of the WebEndpointExample should be close to 0 seconds. (It doesn't do any work; it awaits for the DoSomethingForSomeSecondsAsync to complete.)
However, the agent still measures its execution time as approximately 5 seconds. This is due to the agent's inability to detect blocked time (not CPU time) when a method is awaiting for another. Hence the total time is reported as 10 seconds, which is greater than the response time (approximately 5 seconds).
At the same time, the agent cannot assume calling to async methods would always block the caller for the entire time. The next example demonstrates this:
async Task<string> WebEndpointExample()
var task = DoSomethingForSomeSecondsAsync(5);
[MethodImpl(MethodImplOptions.NoInlining)]
private static async Task DoSomethingForSomeSecondsAsync(int seconds)
await Task.Delay(TimeSpan.FromSeconds(seconds));
In this example, the response time is still approximately 5 seconds, but the actual execution time of the WebEndpointExample is no longer approximately 0.