Reusing S3 Connection in Threads
See original GitHub issueI am attempting an upload of files to S3 using concurrent.futures.ThreadPoolExecutor
in AWS Lambda. This is a sample of my code:
from concurrent import futures
def my_lambda(event, context):
def upload_to_s3(file, key):
s3.Bucket(MY_BUCKET).upload_file(file, key)
with futures.ThreadPoolExecutor(max_workers=1000) as executor:
todo = []
for f in files:
future = executor.submit(upload_to_s3, f, key)
todo.append(future)
results = []
for future in futures.as_completed(todo):
res = future.result()
results.append(res)
It seems all the files do get upload to S3, but there doesn’t seem to be any time improvement over a sequential upload. I am also getting these logs in CloudWatch:
Connection pool is full, discarding connection: s3-us-west-2.amazonaws.com
Did some research and according to this article it is not possible to reuse the connection to S3 since boto3 isn’t thread-safe.
Would like to know if this is indeed correct and if there is a solution to this?
Possibly related: #1128
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Improve transfer performance of sync ... - Amazon AWS
I'm using the AWS Command Line Interface (AWS CLI) sync command to transfer data on Amazon Simple Storage Service (Amazon S3).
Read more >AmazonS3 connection management - Stack Overflow
All client classes in the Java SDK are thread safe, so usually it is a better idea to re-use a single client than...
Read more >Amazon S3 Client :: Quarkiverse Documentation - GitHub Pages
Configuration property Type Default
boolean false
string localstack
AWS SDK client configurations Type Default
Read more >AWS S3 Connection Pool Error - Google Groups
TransferManager , like all the client classes in the AWS SDK for Java, is thread safe. Call TransferManager.shutdownNow() to release the resources once...
Read more >AWS S3 with Java - Reactive Support - Baeldung
This means that the same thread keeps going on handling those events – which can originate from any of the active client connections...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This link refers to
resources
rather thanclients
. Each resource has a meta attribute which holds a boto client under the hood. It sounds to me that the resource holds additional information which makes it thread unsafe, while the client itself might be thread safe. @JordonPhillips Can you please elaborate?@JordonPhillips Is there some documentation that describes boto3 S3 client thread safety?
I can only find this about the thread safety, and it isn’t explicit about the thread safety. https://boto3.amazonaws.com/v1/documentation/api/latest/guide/resources.html?highlight=multithreading#multithreading-multiprocessing