-
-
Notifications
You must be signed in to change notification settings - Fork 250
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
Memory leak in fetch #675
Comments
Fetching a single email with a 10Mb attachment seems to make the problem worse:
|
Hmm. I don't have any concrete ideas, but of course this needs to be fixed. It could be caused by some global variable in the exchangelib package ballooning, but I'm hard pressed so see which it could be. It would be nice to see how memory is distributed in the |
Some further insight:
inside
inside
inside
Maybe requests has a memory leak? |
That's a possible explanation. A lot is happening in |
@dsanghan Did you get anywhere with this issue? I haven't had time to debug this yet. |
@ecederstrand I tried replacing requests with urllib3 but didn't see any improvement in memory. So for now, I've replaced fetching the Another thing I noticed was that ElementTree seems to be using a lot of memory when parsing large soap responses, so that might be worth exploring. |
@ecederstrand Figured it out - it's the thread pool that's leaking. In a server environment that is running 1000's of accounts, the pool is creating sessions_per_account * threads_per_session = 16 new threads per account, basically causing it to leak ~150MB every few minutes as a new account spools up. Removing the The 1000's of threads create their own context's that don't show up in memory_profiler, or heapy, or mprof so it was fairly hard to debug. A simple way to reproduce the issue is to use the above example. A single fetch ends up creating 20 threads. Otherwise, I didn't find any major leaks - almost all objects are properly reclaimed apart from the few cached properties. Might be worth considering adding an option to not use |
Great work, @dsanghan! I'm reopening since this will affect a lot of users. We need to find a solution for this problem in exchangelib. |
The ThreadPool memory leak may actually have been fixed in Python in 3.8.0: python/cpython@3766f18 |
We're using
exchangelib
for a large number of exchange accounts and last month updated our fork to latest master and started seeing a massive spike in virtual memory consumption (several GB over a few hours). On profiling it, we isolated it tofetch
. We wrote a small test case to verify that this is indeed the case and profiled it withmemory_profiler
using the latest release ofexchangelib
. The leak increases in like with the number of emails fetched.With 10 emails:
With 20 emails:
To be clear, the spike is in virtual memory and not committed memory, but once you hit something like ~20GB in virtual memory, the scripts crash. Any suggestions?
The text was updated successfully, but these errors were encountered: