-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 #2047
Comments
The way i get AWS client:
I used 2 process and multy green threads to make requests.And there is only one |
@itachaaa - Thank you for your post. It is recommended to create a resource instance for each thread / process in a multithreaded or multiprocess application rather than sharing a single instance among the threads / processes. Are you creating boto3 session from botocore session ? Can you please provide me your exact code sample that resulting in memory leak ? |
Thanks for reply. |
And only when there is throwning lots of exception the memory will increase, otherwise won't. |
@itachaaa - Thanks for the reply. Is it possible for you to provide me a code sample so that i can try reproduce the issue ? Without looking at the code it is a little difficult for me to find out the exact cause. |
here is my test code:
and let it throw errors a lots such as |
@itachaaa - Thank you for providing me the sample code. Marking this as bug. I am able to reproduce the issue with this script: import os
import boto3
import botocore
import resource
import psutil
from resource import *
import matplotlib.pyplot as pp
import sys
from botocore.config import Config
from eventlet.greenpool import GreenPool
used =[]
def get_data():
client = boto3.client('ec2',config = Config(retries={'max_attempts':0},connect_timeout=5, read_timeout=5))
client.describe_instances()
pool = GreenPool(10000)
for i in range(100000):
process = psutil.Process(os.getpid())
memory = process.memory_info().rss/1024/1024
used.append(memory)
pool.spawn_n(get_data)
pp.plot(used)
pp.show() |
I would like to ask if you have a situation where the network environment is not very good and sometimes throws an exception when you reproduce it. |
I am also tracking down a memory leak. When running a Flask application and looping through Running in lambda the following is a graph of memory from cloudwatch metrics filter: |
Is there an update or workaround for this problem? |
Creating one session per thread and reusing them across ThreadPool mitigated the issue for us. Snippet for import threading
from aiobotocore.session import AioSession, get_session
# NOTE: botocore has a memory leak in Session objects. Recommended workaround is to cache the session object locally per thread.
# See https://github.com/boto/botocore/issues/2047
_aio_session_cache = threading.local()
def _cached_session() -> AioSession:
if not hasattr(_aio_session_cache, "session"):
_aio_session_cache.session = get_session()
return _aio_session_cache.session |
I ran my FastAPI app and
and
I'm using |
Please fill out the sections below to help us address your issue.
What issue did you see ?
When I call the AWS interface in large numbers, and cannot connect to the corresponding area due to network reasons, an EndpointConnectionError is thrown. As time goes by, the memory occupied by my process will continue to increase, and the maximum observed is currently 6G. Using gc and pyrasite to check, it is found that gc.garbage is [], and the data type that takes up the most memory is str or unicode. The unicode description is the document description of DescribeInstancesRequest in service-2.json.
The library versions I use: boto3-1.12.24, botocore-1.15.24, urllib3-1.21.1
Steps to reproduce
If you have a runnable example, please include it as a snippet or link to a repository/gist for larger code examples.
Debug logs
Full stack trace by adding
to your code.
The text was updated successfully, but these errors were encountered: