Created
November 18, 2014 01:53
-
-
Save pda/5dcf54410b696072fcbd to your computer and use it in GitHub Desktop.
thumbor_aws async/blocking debugging.
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
#!/usr/bin/env ruby | |
require "open-uri" | |
require "benchmark" | |
def main | |
urls = ARGV | |
results = Queue.new | |
threads = urls.map do |url| | |
puts "dispatching #{url}" | |
sleep(0.1) | |
Thread.new do | |
results << [url, Benchmark.realtime { open(url) }] | |
end | |
end | |
threads.each do |t| | |
url, seconds = results.pop | |
puts "%d ms for %s" % [seconds * 1000, url] | |
end | |
end | |
main |
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
$ ./race.rb http://localhost:8888/unsafe/sleep/{10,1000,100,10000,500} | |
dispatching http://localhost:8888/unsafe/sleep/10 | |
dispatching http://localhost:8888/unsafe/sleep/1000 | |
dispatching http://localhost:8888/unsafe/sleep/100 | |
dispatching http://localhost:8888/unsafe/sleep/10000 | |
dispatching http://localhost:8888/unsafe/sleep/500 | |
89 ms for http://localhost:8888/unsafe/sleep/10 | |
228 ms for http://localhost:8888/unsafe/sleep/100 | |
1024 ms for http://localhost:8888/unsafe/sleep/500 | |
2028 ms for http://localhost:8888/unsafe/sleep/1000 | |
20024 ms for http://localhost:8888/unsafe/sleep/10000 |
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
$ ./race.rb http://localhost:8888/unsafe/sleep/{10,1000,100,10000,500} | |
dispatching http://localhost:8888/unsafe/sleep/10 | |
dispatching http://localhost:8888/unsafe/sleep/1000 | |
dispatching http://localhost:8888/unsafe/sleep/100 | |
dispatching http://localhost:8888/unsafe/sleep/10000 | |
dispatching http://localhost:8888/unsafe/sleep/500 | |
78 ms for http://localhost:8888/unsafe/sleep/10 | |
2030 ms for http://localhost:8888/unsafe/sleep/1000 | |
2168 ms for http://localhost:8888/unsafe/sleep/100 | |
22108 ms for http://localhost:8888/unsafe/sleep/10000 | |
23051 ms for http://localhost:8888/unsafe/sleep/500 |
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
require "sinatra" | |
require "base64" | |
get "/sleep/:milliseconds" do | |
milliseconds = Integer(params[:milliseconds]) | |
seconds = Rational(milliseconds, 1000) | |
sleep(seconds) | |
headers "Content-Type" => "image/png" | |
body Base64.decode64( | |
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVQYV2P4DwABAQEAWk1v8QAAAABJRU5ErkJggg==" | |
) | |
end | |
not_found do | |
headers "Content-Type" => "text/plain" | |
body "404 Not Found" | |
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
LOADER = 'thumbor_aws.loaders.s3_loader' | |
STORAGE = 'thumbor.storages.no_storage' | |
S3_ALLOWED_BUCKETS = None | |
S3_LOADER_BUCKET = None | |
AWS_ACCESS_KEY = None | |
AWS_SECRET_KEY = None |
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
--- a/thumbor_aws/loaders/s3_loader.py 2014-11-17 16:14:15.000000000 -0800 | |
+++ b/thumbor_aws/loaders/s3_loader.py 2014-11-17 16:13:53.000000000 -0800 | |
@@ -3,6 +3,7 @@ | |
from boto.s3.connection import S3Connection | |
from boto.s3.bucket import Bucket | |
from boto.s3.key import Key | |
+from boto.s3.connection import OrdinaryCallingFormat | |
connection = None | |
@@ -35,7 +36,11 @@ | |
# Store connection not bucket | |
conn = S3Connection( | |
context_config.AWS_ACCESS_KEY, | |
- context_config.AWS_SECRET_KEY | |
+ context_config.AWS_SECRET_KEY, | |
+ is_secure = False, | |
+ host = '127.0.0.1', | |
+ port = 4567, | |
+ calling_format = OrdinaryCallingFormat(), | |
) | |
return conn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment