Skip to content
dallasmarlow edited this page Apr 23, 2012 · 17 revisions
require 'benchmark'
require 's3_multi_upload'

config = {
  :access_key_id     => 'xxx',
  :secret_access_key => 'xxx',
  :bucket            => :s3_multi_upload,
  :file              => 'ubuntu-12.04-beta2-dvd-amd64.iso', # 1.6 gb
}

# setup s3 client for serial test
AWS.config :access_key_id     => config[:access_key_id],
           :secret_access_key => config[:secret_access_key]

s3     = AWS::S3.new
bucket = s3.buckets.create config[:bucket]


Benchmark.bm(10) do |benchmark|

  # multipart upload in serial
  benchmark.report 'serial' do
    object = bucket.objects[config[:file]]
    object.write :file => config[:file],
                   :multipart_threshold => 25 * 1024 ** 2 # 25 mb
  end

  # threaded multipart upload
  benchmark.report 'parallel' do
    object = S3_Multi_Upload::Upload.new :access_key_id     => config[:access_key_id],
                                         :secret_access_key => config[:secret_access_key],
                                         :bucket            => config[:bucket],
                                         :file              => config[:file],
                                         :threads           => 20,
                                         :chunk_size        => {25 => :mb}
  end

end
Clone this wiki locally