This repository has been archived by the owner on Nov 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new http cache support, and some fixes
- Loading branch information
Peter Kieltyka
committed
Nov 10, 2011
1 parent
5d38f61
commit 1b97720
Showing
19 changed files
with
335 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/usr/bin/env ruby | ||
$:<< '../lib' << 'lib' | ||
############################################################################### | ||
# | ||
############################################################################### | ||
|
||
# require 'uber-s3' | ||
# | ||
# s3 = UberS3.new({ | ||
# :access_key => 'x', | ||
# :secret_access_key => 'y', | ||
# :bucket => 'nutestbucket', | ||
# :adapter => :em_http_fibered, | ||
# :concurrency => 100 | ||
# }) | ||
|
||
require 'eventmachine' | ||
require 'em-http' | ||
require 'em-synchrony' | ||
require 'em-synchrony/em-http' | ||
|
||
require 'ruby-debug' | ||
|
||
CONCURRENCY = 10 | ||
|
||
EM.run do | ||
pool = EM::Synchrony::ConnectionPool.new(:size => CONCURRENCY) do | ||
EM::HttpRequest.new('http://www.google.ca/') | ||
end | ||
|
||
p = { :keepalive => true } | ||
num = 40 | ||
counter = num | ||
|
||
num.times do | ||
Fiber.new { | ||
x = pool.get(p) | ||
puts "GOT IT #{x.response.length}" | ||
counter -= 1 | ||
|
||
EM.stop if counter <= 0 | ||
}.resume | ||
end | ||
|
||
end | ||
|
||
|
||
|
||
__END__ | ||
############################################################################### | ||
# This example demonstrates the combined power of eventmachine+fibers. | ||
# Notice how the example code is exactly the same as basic.rb | ||
# except instead it's using a non-blocking http client.. boom. | ||
# | ||
# Btw, make sure to bundle up first... | ||
############################################################################### | ||
|
||
require 'uber-s3' | ||
|
||
s3 = UberS3.new({ | ||
:access_key => 'x', | ||
:secret_access_key => 'y', | ||
:bucket => 'nutestbucket', | ||
:adapter => :em_http_fibered | ||
}) | ||
|
||
x = Proc.new do | ||
# Traverse all objects in the bucket -- beware :) | ||
# This will only load the keys and basic info of the object, not the data | ||
s3.objects('/').each do |obj| | ||
puts obj | ||
# puts obj.value # this will actually fetch the data on demand | ||
end | ||
end | ||
|
||
EM.run do | ||
Fiber.new { | ||
x.call | ||
EM.stop | ||
}.resume | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module UberS3::Operation::Object | ||
module HttpCache | ||
|
||
def self.included(base) | ||
base.send :extend, ClassMethods | ||
base.send :include, InstanceMethods | ||
|
||
base.instance_eval do | ||
attr_accessor :cache_control, :expires, :pragma, :ttl | ||
end | ||
end | ||
|
||
module ClassMethods | ||
end | ||
|
||
module InstanceMethods | ||
|
||
# Helper method that will set the max-age for cache-control | ||
def ttl=(seconds) | ||
@ttl = seconds | ||
self.cache_control = "public,max-age=#{seconds}" | ||
end | ||
|
||
# Expires can take a time or string | ||
def expires=(val) | ||
if val.is_a?(String) | ||
self.expires = val | ||
elsif val.is_a?(Time) | ||
# RFC 1123 format | ||
self.expires = val.strftime("%a, %d %b %Y %H:%I:%S %Z") | ||
end | ||
end | ||
|
||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
class UberS3 | ||
VERSION = '0.1.4' | ||
VERSION = '0.1.5' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require 'bundler' | ||
Bundler.setup | ||
|
||
require 'ruby-debug' | ||
require 'eventmachine' | ||
require 'em-http-request' | ||
require 'fiber' | ||
|
||
|
||
def http_get(url) | ||
f = Fiber.current | ||
|
||
req = EM::HttpRequest.new(url).get | ||
req.callback { f.resume(req) } | ||
req.errback { f.resume(req) } | ||
|
||
Fiber.yield | ||
end | ||
|
||
EM.run do | ||
urls = [ | ||
['http://nulayer.com/', 'http://twitter.com/#!/nupeter/'], | ||
['http://google.ca/', 'http://twitter.com/#!/jeffbrenner/'], | ||
['http://facebook.com/', 'http://twitter.com/#!/nulayer/'], | ||
['http://data.crowdreel.com.s3.amazonaws.com/2011/05/17-02/1f55685cc1e9c91d80079a49485c718b1f53d97f.jpg', 'http://twitter.com/#!/jack/'], | ||
['http://data.crowdreel.com.s3.amazonaws.com/2011/05/17-02/54acc4f94b81268982aab94e0d273693962741ab.jpg', 'http://twitter.com/#!/ev/'], | ||
['http://data.crowdreel.com.s3.amazonaws.com/2011/05/17-02/66ca6cb906f1b517cc576477b3d69e155dc21284.jpg', 'http://twitter.com/#!/presslyapp/'], | ||
['http://data.crowdreel.com.s3.amazonaws.com/2011/05/17-02/cfeb066a4f0ba75a2081898a6c750d371aafd7e9.jpg', 'http://twitter.com/#!/crpwdreel/'] | ||
] | ||
|
||
puts "init" | ||
|
||
Fiber.new { | ||
# url = 'http://nulayer.com/' | ||
# ret = http_get(url) | ||
# puts ret.response_header.status.to_s+" from #{url}" | ||
|
||
urls.each do |url| | ||
Fiber.new { | ||
puts "A start: #{url[0]}" | ||
ret = http_get(url[0]) | ||
puts "A done: #{url[0]} -- #{ret.response_header.status.to_s}" | ||
|
||
Fiber.new { | ||
puts "B start: #{url[1]}" | ||
ret = http_get(url[0]) | ||
puts "B done: #{url[1]} -- #{ret.response_header.status.to_s}" | ||
}.resume | ||
}.resume | ||
end | ||
}.resume | ||
|
||
puts "eof" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'fiber' | ||
|
||
def woot | ||
x = nil | ||
|
||
f = Fiber.new { |k| | ||
puts k | ||
y = Fiber.yield 1 | ||
puts y | ||
x = "hello" | ||
2 | ||
} | ||
|
||
puts f.resume(5) | ||
puts f.resume(6) | ||
puts x | ||
|
||
end | ||
|
||
woot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.