Uber-S3
A simple, but very fast, S3 client for Ruby supporting
synchronous (net-http) and asynchronous (em+fibers) io.
Examples
require 'uber-s3'
s3 = UberS3.new({
:access_key => 'abc',
:secret_access_key => 'def',
:bucket => 'funbucket',
:adapter => :em_http_fibered
})
s3.store('/test.txt', 'Look ma no hands')
s3.store('test2.txt', 'Hey hey', :access => :public_read)
o = s3.object('/test.txt')
o.value = 'Look ma no hands'
o.save
o = UberS3::Object.new(s3.bucket, '/test.txt', 'heyo')
o.save
s3['/test.txt'].class
s3['/test.txt'].value
s3.get('/test.txt').value
s3.exists?('/anotherone')
o.access = :private
o.access = :public_read
o.delete
options = { :access => :public_read, :content_type => 'text/plain' }
o = UberS3::Object.new(client.bucket, '/test.txt', 'heyo', options)
o.save
o = s3.object('/test.txt')
o.value = 'Look ma no hands'
o.access = :public_read
o.content_type = 'text/plain'
o.save
s3.objects('/path').each {|obj| puts obj }
Ruby version notes
- Tested on MRI 1.9.2, MRI 1.9.3 (net_http / em_http_fibered adapters)
- Tested on JRuby 1.7-dev in 1.9 mode (net_http)
- Ruby 1.8.7 works for net/http clients, em_http_fibered adapter requires fibers
Other notes
- If Nokogiri is available, it will be automatically used instead of REXML
TODO
- Refactor UberS3::Object class, consider putting the operations/headers into separate classes
- Better exception handling and reporting
- Query string authentication -- neat feature for providing temporary public access to a private object
- Object versioning support
Benchmarks
Benchmarks were run with a speedy MBP on a 10Mbit connection
Saving lots of 1KB files
user system total real
saving 100x1024 byte objects (net-http) 0.160000 0.080000 0.240000 ( 26.128499)
saving 100x1024 byte objects (em-http-fibered) 0.080000 0.030000 0.110000 ( 0.917334)
Saving lots of 500KB files
user system total real
saving 100x512000 byte objects (net-http) 0.190000 0.740000 0.930000 ( 91.559123)
saving 100x512000 byte objects (em-http-fibered) 0.230000 0.700000 0.930000 ( 45.119033)
Conclusion
Yea... async adapter dominates. The 100x1KB files were 29x faster to upload, and the 100x500KB files were only 2x faster, but that is because my upload bandwidth was tapped.
S3 API Docs
License
MIT License - Copyright (c) 2012 Nulayer Inc.