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
Transport causes CPU Spikes on Larger Envelopes #2384
I did some profiling today: (because sending is done in a worker thread, I profiled them on my local machine because in sentry we sould have not enough samples)
So there is nothing that jumps out. Most of the time is spent in the http lib (which was kind of our guess). I tried to disable SSL certificate verification, but this made not difference at all.
One thing of not is that sending 10 envelopes takes around 350ms and sending 50 envelopes takes 2500ms (no matter what size the attachments) So that is not linear growth there.
We could create an AsyncHttpTransport (swapping out urllib3 with aiohttp) to see if the result changes drastically. But this is not done in a day.
Another note. I also tracked the cpu utilization of my test process. It maxed out at between 54% (10 small envelopes) 56% (10 large envelopes), and 61% (50 large envelopes). So I could not reproduce a cup utilization spike.
Ok, after same debugging I did not find the root cause, so I also consulted with the admins of the urllib3 discord and one thing the immediately told us that we should increase the pool size. Another thing was that decoding TLS traffic uses cpu but there is a feature to turn it of. This is what I did.
It did not got rid of all the CPU spikes in my tests setup but instead of 1 in 3-4 runs, the cpu only spikes in 1 in 7-8 runs. So it is better now.
Another thing of notice: OpenSSL 3 has performance problems: python/cpython#95031
Our server still has OpenSSL 1.1.1 so we are not affected, but when we update, we will. (and other customers might use OpenSSL 3 and are affected by those performance problems)
Activity
sl0thentr0py commentedon Oct 6, 2023
possible urllib3 stuff
psf/requests#1910
antonpirker commentedon Oct 10, 2023
I did some profiling today: (because sending is done in a worker thread, I profiled them on my local machine because in sentry we sould have not enough samples)
Profling setup:
I used
profiling_sample_rate=1.0in the sentry_sdk.init() for profiling. Additionally I patchedI profiled the background workers thread
.run()method and dump the data onflush(): https://github.com/getsentry/sentry-python/pull/2439/filesa) send 10 envelopes with big attachments (10000 hello worlds):
https://sentry-sdks.sentry.io/profiling/profile/sentry-python/6b7fc1ca0e30427cbf9d76ff2e1998dd/flamegraph/
b) send 50 envelopes with big attachments (10000 hello worlds):

https://sentry-sdks.sentry.io/profiling/profile/sentry-python/d446df68dd324870a5d0fb416a29e29b/flamegraph/
c) send 50 envelopes with small attachments (10 hello worlds):
https://sentry-sdks.sentry.io/profiling/profile/sentry-python/ac9a8a1ae4f648a582ce375fe6e1e474/flamegraph/
So there is nothing that jumps out. Most of the time is spent in the http lib (which was kind of our guess). I tried to disable SSL certificate verification, but this made not difference at all.
One thing of not is that sending 10 envelopes takes around 350ms and sending 50 envelopes takes 2500ms (no matter what size the attachments) So that is not linear growth there.
We could create an AsyncHttpTransport (swapping out urllib3 with aiohttp) to see if the result changes drastically. But this is not done in a day.
antonpirker commentedon Oct 11, 2023
Another note. I also tracked the cpu utilization of my test process. It maxed out at between 54% (10 small envelopes) 56% (10 large envelopes), and 61% (50 large envelopes). So I could not reproduce a cup utilization spike.
antonpirker commentedon Oct 16, 2023
Ok, after same debugging I did not find the root cause, so I also consulted with the admins of the urllib3 discord and one thing the immediately told us that we should increase the pool size. Another thing was that decoding TLS traffic uses cpu but there is a feature to turn it of. This is what I did.
It did not got rid of all the CPU spikes in my tests setup but instead of 1 in 3-4 runs, the cpu only spikes in 1 in 7-8 runs. So it is better now.
antonpirker commentedon Oct 16, 2023
Another thing of notice: OpenSSL 3 has performance problems: python/cpython#95031
Our server still has OpenSSL 1.1.1 so we are not affected, but when we update, we will. (and other customers might use OpenSSL 3 and are affected by those performance problems)