AWS: Speed up copy of large number of very small files

Viewed 1440

I have a single bucket with a large number of very small text files (betwen 500 bytes to 1.2k). This bucket currently contains over 1.7 Million files and will be ever increasing.

The way that I add data to this bucket is by generating batches of files (in the order 50.000 files) and transfering those files into the bucket.

Now the problem is this. If I transfer the files one by one in a loop it takes an unbareably long amount of time. So if all the files a in a directory origin_directory I would do

aws s3 cp origin_directory/filename_i s3://my_bucket/filename_i

I would do this command 50000 times.

Right now I'm testing this on a set of about 280K files. Doing this would take approximately 68 hours according to my calculations. However I found out that I can sync:

aws s3 sync origin_directory s3://my_bucket/

Now this, works much much faster. (Will take about 5 hours, according to my calculations). However, the sync needs to figure out what to copy (files present in the directory and not present in the bucket). Since the files in the bucket will be ever increasing, I'm thinking that this will take longer and longer as times moves on.

However, since I delete the information after every sync, I know that the sync operation needs to transfer all files in that directory.

So my question is, is there a way to start a "batch copy" similar to the sync, without actually doing the sync?

2 Answers

You can use:

aws s3 cp --recursive origin_directory/ s3://my_bucket/

This is the same as a sync, but it will not check whether the files already exist.

Also, see Use of Exclude and Include Filters to learn how to specify wildcards (eg all *.txt files).

When copying a large number of files using aws s3 sync or aws s3 cp --recursive, the AWS CLI will parallelize the copying, making it much faster. You can also play with the AWS CLI S3 Configuration to potentially optimize it for your typical types of files (eg copy more files simultaneously).

Related