-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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 after updating to 1.25.0 #3614
Comments
Hi @ron8mcr thanks for reaching out. In the boto3 CHANGELOG you can see the following change introduced in 1.25.0:
The S3 endpoint ruleset is particularly large, which could explain the increased memory usage you're describing. Do you see the issue when using other services? What are you using to profile memory usage? And have you tried using |
Yes, it is expected that memory usage should increase. However, memory usage increases after each API call, and the more iterations happen - the more RAM required.
Checked with
Actually this problem was found by Cloudwatch agent, later confirmed with sample script using
Yes, P.S. I've add Sample scriptimport boto3
import os
import boto3
import psutil
import matplotlib.pyplot as pp
memory_usages = []
for i in range(150):
process = psutil.Process(os.getpid())
memory = process.memory_info().rss/1024/1024
memory_usages.append(memory)
boto3.Session().client('s3').list_buckets()
pp.plot(memory_usages)
pp.show() |
I think this issue starts from In |
After bringing this issue up for discussion with the team I wanted to clarify a couple of things. The behavior originally described here is really increased memory usage rather than a memory leak. As previously mentioned, the new endpoint rulesets files recently added for services like S3 are large (~1.6MB) . But the excessive memory usage problem here is due to the accumulation of Sessions. If you reuse sessions, then you don't need to keep reloading the same large JSON files. Maybe this is something that could be better clarified in the documentation. |
Use self.resolve_endpoint = lru_cache(maxsize=CACHE_SIZE)(self.resolve_endpoint) If global cache is still wanted, then refactor it to be a static method, or even better, a function. References: |
@tim-finnigan @alexanderGerbik @hemslo Meanwhile, I've tried to use it and everything worked perfect for my case. @alexanderGerbik @hemslo much thanks for your suggestions |
Hi ron8mcr, thanks for reporting this and doing the deep dive. We have been researching this in parallel to understand what is happening because we have not seen the same behavior in our own integration testing. The root cause of what you are seeing is the large number of botocore sessions that get created in your code snippet. Creating new session objects is known to be expensive. Each session object not only consumes a large amount of memory, it is also slow to create because several files get loaded from the file system to create the object. (Coincidentally, those files do not get cached across Session objects and The reason you are observing high memory usage with the As a path forward, we would recommend that you review your code for opportunities to reduce the number of separate botocore Sessions. This will probably have memory and runtime benefits beyond the problem described in this post. We will also review your PR because it mitigates the problem for those rare situations where a large number of |
We have use cases of large number of It would be nice if we can cache _load_file across sessions, it consumes 300+ MB in our peak usage. |
Hi @tim-finnigan,
Actually, we found this within different
Thanks in advance! |
Addressed in boto/botocore#2934 |
Describe the bug
Memory leaks started to happen after updating to
boto3>=1.25.0
.Expected Behavior
No changes in memory usage after updating the version
Current Behavior
Memory usage increases after each execution of
Reproduction Steps
Here is smallest script to reproduce the problem:
Running this with
boto3<1.25.0
requires ~80MB of memory:Running this with
boto3>=1.25.0
requires ~~177MB:The more iterations for
range
I set, the more difference in memory usage.Possible Solution
No response
Additional Information/Context
Found this in context of
Django
app and https://github.com/revsys/django-health-check (which perform periodic calls to S3 bucket)I've checked similar issues:
gc.collect()
is not showing any effect #3541But these issues specify earlier versions of SDK, while I've faced this problem just with 1.25.0+
SDK version used
1.25.0
Environment details (OS name and version, etc.)
ManjaroLinux 22.0.4
The text was updated successfully, but these errors were encountered: