You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Increased CPU and memory overhead while profiling #3199
The CPU overhead is around around +70%, which is seen through google cloud monitoring system.
The following Sentry packages are used:
Sentry 4.1.2
Sentry.AspNetCore 4.1.2
Sentry.Profiling 4.1.2
Could we have some details about what the app is doing? With a repro we can look exactly what's going on and make improvements but with the currently provided information it's hard for us to figure out where the problem is.
Is this a web server? How many requests in parallel are running?
If this has high thrughput, changing sample rate to:
@bruno-garcia I tried to put sample rates to 0.001 and there is still quite a significant spike (from 7 % CPU -> 40 % CPU)
In fact, it was about the same as with sampling rate 1.0, which is weird...
The behaviour is, it first jumps to 60% and then stabilises at 40%.
It is a web server, but in sandbox environment, and we are running 20 workers in parallel
I have mentioned before that we are using hang fire to queue background jobs and I have noticed call like that: Sentry.AspNetCore.SentryTracingMiddleware.InvokeAsync(HttpContext context). But when it is a hangfire background job HttpContext will be null, so that might somehow explain what is going on
I tried to put sample rates to 0.001 and there is still quite a significant spike (from 7 % CPU -> 40 % CPU)
In fact, it was about the same as with sampling rate 1.0, which is weird...
This didn't come up during our tests so I'm a bit surprised but I wonder if it might be the overhead of the .NET profiler itself which unfortunately has a high frequency and we down sample after the fact.
I have mentioned before that we are using hang fire to queue background jobs and I have noticed call like that: Sentry.AspNetCore.SentryTracingMiddleware.InvokeAsync(HttpContext context). But when it is a hangfire background job HttpContext will be null, so that might somehow explain what is going on
I wonder if this is to get the transaction name automatically.
Do you get the overhead without Profiling turned on? Just keep transactions (TracesSampleRate set to some value)
By any chance in the profiles in Sentry, do you see any frames from Sentry that seem to be taking significant part time?
Thanks @bruno-garcia. Without profiling it works like a charm without any noticable overhead.
I could not find anything from Sentry taking a lot of time, in fact I couldn't see any sentry frames at all - which is weird, right, I should be able to see sentry-related process there...
@vaind ran a trace for almost 3 hours, ending just now:
root@b4ee333c5f1c:~/site/wwwroot# dotnet-trace collect --profile cpu-sampling -p 106 -o /dev/null
Provider Name Keywords Level Enabled By
Microsoft-DotNETCore-SampleProfiler 0x0000F00000000000 Informational(4) --profile
Microsoft-Windows-DotNETRuntime 0x00000014C14FCCBD Informational(4) --profile
Process : /usr/share/dotnet/dotnet
Output File : /dev/null
[00:02:50:37] Recording trace 0.00 (B)
Press <Enter> or <Ctrl+C> to exit... (B)
Stopping the trace. This may take several minutes depending on the application being traced.
Trace completed.
(output to dev/null to avoid file storage issues and I/O penalties)
Result in CPU was high, but also profiling @ 100%:
Response times remained good (the longer ones are incorrect measuring on long-lived WebSockets SignalR conns):
No 5xx or 499 thrown during this period:
Average memory working set was constant w/ profiler active (no 2x jump like with the Sentry profiler):
Console / App / HTTP logs are clean. No app service restarts since I turned off the Sentry profiler yesterday afternoon.
I suspect SignalR / WebSockets issues w/ the Sentry profiler remain.
I've identified at least one memory leak in perfview EventPipe processing where it calls GC.KeepAlive() on objects so they never get freed. However, I can still see the memory growing, although not on the managed side so there may be something else going on as well.
I'll post a PR decreasing the circular buffer we use when setting up a diagnostic session but other than that, the main problem seems to be with object pinning in perfview and changing that would require changing quite a few things. In short, EventPipeScource doesn't copy incoming buffer but instead maps structs (EventPipeEventHeader) directly onto the buffer (unsafe but OK if pinned). To amplify the problem, parts of these structs are then referenced directly (as pointers) and it's not clear to me whether objects containing these copied pointers would live outside the event handles (it seems like they would). I'm not sure about the scope of the changes needed to make this work without pinning (or without a pinning handle leak while still staying safe), but I have a feeling it would require a lot of effort.
Activity
bruno-garcia commentedon Mar 6, 2024
cc @vaind
Could we have some details about what the app is doing? With a repro we can look exactly what's going on and make improvements but with the currently provided information it's hard for us to figure out where the problem is.
Is this a web server? How many requests in parallel are running?
If this has high thrughput, changing sample rate to:
Does that reduce the CPU overhead considerably?
saschash commentedon Mar 7, 2024
@bruno-garcia I tried to put sample rates to 0.001 and there is still quite a significant spike (from 7 % CPU -> 40 % CPU)
In fact, it was about the same as with sampling rate 1.0, which is weird...
The behaviour is, it first jumps to 60% and then stabilises at 40%.
It is a web server, but in sandbox environment, and we are running 20 workers in parallel
I have mentioned before that we are using hang fire to queue background jobs and I have noticed call like that: Sentry.AspNetCore.SentryTracingMiddleware.InvokeAsync(HttpContext context). But when it is a hangfire background job HttpContext will be null, so that might somehow explain what is going on
bruno-garcia commentedon Mar 10, 2024
This didn't come up during our tests so I'm a bit surprised but I wonder if it might be the overhead of the .NET profiler itself which unfortunately has a high frequency and we down sample after the fact.
I wonder if this is to get the
transactionname automatically.Do you get the overhead without Profiling turned on? Just keep transactions (
TracesSampleRateset to some value)By any chance in the profiles in Sentry, do you see any frames from Sentry that seem to be taking significant part time?
saschash commentedon Mar 11, 2024
Thanks @bruno-garcia. Without profiling it works like a charm without any noticable overhead.
I could not find anything from Sentry taking a lot of time, in fact I couldn't see any sentry frames at all - which is weird, right, I should be able to see sentry-related process there...
60 remaining items
haneytron commentedon Jun 6, 2024
@vaind ran a trace for almost 3 hours, ending just now:
(output to dev/null to avoid file storage issues and I/O penalties)
Result in CPU was high, but also profiling @ 100%:
Response times remained good (the longer ones are incorrect measuring on long-lived WebSockets SignalR conns):
No 5xx or 499 thrown during this period:
Average memory working set was constant w/ profiler active (no 2x jump like with the Sentry profiler):
Console / App / HTTP logs are clean. No app service restarts since I turned off the Sentry profiler yesterday afternoon.
I suspect SignalR / WebSockets issues w/ the Sentry profiler remain.
vaind commentedon Jun 7, 2024
I've identified at least one memory leak in perfview EventPipe processing where it calls
GC.KeepAlive()on objects so they never get freed. However, I can still see the memory growing, although not on the managed side so there may be something else going on as well.vaind commentedon Jun 27, 2024
TLDR: not resolved yet
I'll post a PR decreasing the circular buffer we use when setting up a diagnostic session but other than that, the main problem seems to be with object pinning in perfview and changing that would require changing quite a few things. In short,
EventPipeScourcedoesn't copy incoming buffer but instead maps structs (EventPipeEventHeader) directly onto the buffer (unsafe but OK if pinned). To amplify the problem, parts of these structs are then referenced directly (as pointers) and it's not clear to me whether objects containing these copied pointers would live outside the event handles (it seems like they would). I'm not sure about the scope of the changes needed to make this work without pinning (or without a pinning handle leak while still staying safe), but I have a feeling it would require a lot of effort.vaind commentedon Jul 24, 2024
FYI, I've raised an issue over at dotnet/runtime#105132 for the unmanaged memory growth
bruno-garcia commentedon Oct 1, 2024
@filipnavara has made a fix related to a leak.
I've updated our fork to include the fix. We'll bump the submodule here and make a release.
vaind commentedon Oct 2, 2024
according to my manual testing (running a sample app from #3645 for hours), the memory leak seem to be resolved by #3492
bruno-garcia commentedon Oct 3, 2024
Woo! Thank you @vaind and @filipnavara
I'm closing this issue as resolved.
If you have any issues with our profiling offer, please raise a ticket. We'd like to make sure this is working properly to everyone!