We have a requirement where we need to upload about 2 million files (each approx 30 KB from a EC2 instance to S3). We are using python, boto3 and concurrent.futures modules in order to try to achieve this. The following is the pseudo code
import concurrent.futures
from concurrent.futures import ThreadPoolExecutor
class UploadToS3:
def upload(self, file_path):
try:
s3 = boto3.resource('s3')
bucket = s3.Bucket('xxxxxxxxxx')
destination_file_path = 'yyyyy'
bucket.upload_file(file_path,destination_file_path)
del s3
except (Exception) as e :
print(e)
def upload_files(self, file_paths):
with concurrent.futures.ThreadPoolExecutor(max_workers=2000) as executor:
tracker_futures = []
for file_path in file_paths:
tracker_futures.append(executor.submit(self.upload,file_path))
for future in concurrent.futures.as_completed(tracker_futures):
tracker_futures.remove(future)
del future
However we are finding out that we can upload only ~78000 files per hour, Increasing the number of thread does not have much effect, we believe its because of GIL , when we tried to use ProcessPoolExecutor, we ran in to issues because the boto3 objects are not Pickable. Any suggestions on how to overcome this scenario