Context
My objective is to move to s3, and I want to to that in a fast and robust way. I am trying to run the entire operation in memory and asynchronously (nice to have). Everything seems to work smooth; however, my primary concern is at the step where I upload (I use boto3) the files to S3. It seems that this step becomes very slow (or starts fast and then becomes very slow, as if it is throttled).
What I have tried to do
The function which I use to copy from postgres -> compress -> upload to s3 (happy to share full code if needed) looks like:
async def sync_concurrently(query: str, pool: Pool, client: AioBaseClient, bucket: str):
# Initiate COPY from s3 and log response
query_data = await pg_copy(pool, query)
# Gzip files async
loop = asyncio.get_event_loop()
future = await loop.run_in_executor(EXECUTOR, gzip_data, query_data)
# Initiate upload to s3 and log response
await upload_to_s3(client, bucket, future)
It's worth mentioning that I am using aiobotocore as client to upload to s3 asynchronously, in which the aws upload uses the method client.put_object (documented here). Note that I have also used the native (non-async) boto3 put_object method (along other methods) but that results in the same issue.
What seems not to work as expected
The upload to s3 step takes a long time (about 20 minutes to upload 3 GB file) in comparison to using aws cli (takes a few seconds to upload a 3 GB file).
Other approaches I have tried
- Changing file size: To my understanding, uploading data to s3 with
put_objectneeds to be less than 5GBs, so I tried to upload with different file sizes (500 MB to 3 GB) but I still got the same behaviour - Not using aiobotocore and using aws boto3 (non async approach): The upload still takes a long time
- Using aws boto3
upload_file_obj(documented here) with TransferConfig, similar to how it shown in this answer here: The upload for files start fast and then suddenly throttles down to become very slow
Question
I noticed that when I use aws cli commands (like aws s3 sync) the upload to S3 is significantly (few minutes vs. an hour+) faster than using boto3 functions. Is there something I am doing wrong? How can I make my upload much faster or as fast as the aws cli?
I am happy to provide further details and/or improve my question if needed