-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reducing memory consumption #2831
Reducing memory consumption #2831
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #2831 +/- ##
=============================================
- Coverage 88.414% 88.362% -0.052%
=============================================
Files 92 92
Lines 7164 7175 +11
Branches 1229 1232 +3
=============================================
+ Hits 6334 6340 +6
- Misses 575 580 +5
Partials 255 255 ☔ View full report in Codecov by Sentry. |
Should also look at clearing cyclic links once done with request/connection, so that Sanic itself would not leak memory when used without GC. Some of them are already cleared but surely some loops remain too. |
@Tronic I didn't find any other issues of such type or memory leaks |
But you still had GC enabled? Sanic takes care to clear to avoid cyclic links but I am sure it ain't 100 % yet. This is only relevant once GC is disabled. |
Yes, GC is enabled. I don't think that the basic recommendation of sanic usage is to disable GC |
Definitely not a basic recommendation. It takes a lot of care to avoid/break cycles in all code, user apps included. But for maximal performance you would want it disabled, can make quite a difference at times. |
Memory consumption with disabled gc is low and stable |
I have found that the more requests Sanic processes, the more memory consumption increases. This behavior, as far as I could understand, is relevant only with a sufficiently large number of requests.
After some research, I took an idea from here to make sure that no unnecessary objects remain in memory after processing requests.
Application I used
I used ab to make requests
(it doesn't matter what's in the request body)
So i discovered thousands of
TimerHandle HttpProtocol.check_timeouts
andabort
fromSanicProtocol
(required much more than 10000 requests).My changes solves the memory freeing question, but it also has another side effect: here is rps from ab results before and after my changed - 7273 (main branch) vs 8558 (this branch).
Yes, I know that this is not the most relevant way to measure performance using such requests, but I don't have time to properly test the framework. I can only say that the applications that I develop and use Sanic at least did not slow down after my changes.