mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
setting groundwork for benchs/optimization
This commit is contained in:
parent
7735d7797c
commit
7cd3f1a2ff
3 changed files with 29 additions and 13 deletions
|
@ -2,7 +2,7 @@ require 'rubygems'
|
||||||
require 'benchwarmer'
|
require 'benchwarmer'
|
||||||
require 'right_aws'
|
require 'right_aws'
|
||||||
|
|
||||||
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
||||||
require 'fog/aws'
|
require 'fog/aws'
|
||||||
|
|
||||||
data = File.open(File.expand_path('~/.s3conf/s3config.yml')).read
|
data = File.open(File.expand_path('~/.s3conf/s3config.yml')).read
|
||||||
|
@ -17,7 +17,7 @@ raws = RightAws::S3Interface.new(
|
||||||
)
|
)
|
||||||
raws.logger.level = 3 # ERROR
|
raws.logger.level = 3 # ERROR
|
||||||
|
|
||||||
TIMES = 10
|
TIMES = 100
|
||||||
|
|
||||||
Benchmark.bm(25) do |bench|
|
Benchmark.bm(25) do |bench|
|
||||||
bench.report('fog.put_bucket') do
|
bench.report('fog.put_bucket') do
|
||||||
|
@ -31,13 +31,13 @@ Benchmark.bm(25) do |bench|
|
||||||
|
|
||||||
bench.report('fog.put_object') do
|
bench.report('fog.put_object') do
|
||||||
TIMES.times do |x|
|
TIMES.times do |x|
|
||||||
file = File.open(File.dirname(__FILE__) + '/spec/lorem.txt', 'r')
|
file = File.open(File.dirname(__FILE__) + '/../spec/lorem.txt', 'r')
|
||||||
fog.put_object('fogbench', "lorem_#{x}", file)
|
fog.put_object('fogbench', "lorem_#{x}", file)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
bench.report('raws.put') do
|
bench.report('raws.put') do
|
||||||
TIMES.times do |x|
|
TIMES.times do |x|
|
||||||
file = File.open(File.dirname(__FILE__) + '/spec/lorem.txt', 'r')
|
file = File.open(File.dirname(__FILE__) + '/../spec/lorem.txt', 'r')
|
||||||
raws.put('rawsbench', "lorem_#{x}", file)
|
raws.put('rawsbench', "lorem_#{x}", file)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -63,4 +63,4 @@ Benchmark.bm(25) do |bench|
|
||||||
bench.report('raws.delete_bucket') do
|
bench.report('raws.delete_bucket') do
|
||||||
raws.delete_bucket('rawsbench')
|
raws.delete_bucket('rawsbench')
|
||||||
end
|
end
|
||||||
end
|
end
|
19
benchs/headers_split_vs_match.rb
Normal file
19
benchs/headers_split_vs_match.rb
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
require 'rubygems'
|
||||||
|
require 'benchwarmer'
|
||||||
|
|
||||||
|
COUNT = 1000
|
||||||
|
data = "Content-Length: 100"
|
||||||
|
Benchmark.bmbm(25) do |bench|
|
||||||
|
bench.report('regex') do
|
||||||
|
COUNT.times do
|
||||||
|
header = data.match(/(.*):\s(.*)/)
|
||||||
|
"#{header[1]}: #{header[2]}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
bench.report('split') do
|
||||||
|
COUNT.times do
|
||||||
|
header = data.split(': ')
|
||||||
|
"#{header[0]}: #{header[1]}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -23,9 +23,6 @@ module Fog
|
||||||
end
|
end
|
||||||
|
|
||||||
def request(params)
|
def request(params)
|
||||||
params = {
|
|
||||||
:headers => {}
|
|
||||||
}.merge(params)
|
|
||||||
uri = URI.parse(params[:url])
|
uri = URI.parse(params[:url])
|
||||||
path = "#{uri.path}"
|
path = "#{uri.path}"
|
||||||
if uri.query
|
if uri.query
|
||||||
|
@ -38,6 +35,7 @@ module Fog
|
||||||
end
|
end
|
||||||
|
|
||||||
request = "#{params[:method]} #{path} HTTP/1.1\r\n"
|
request = "#{params[:method]} #{path} HTTP/1.1\r\n"
|
||||||
|
params[:headers] ||= {}
|
||||||
params[:headers]['Host'] = uri.host
|
params[:headers]['Host'] = uri.host
|
||||||
if params[:body]
|
if params[:body]
|
||||||
params[:headers]['Content-Length'] = params[:body].length
|
params[:headers]['Content-Length'] = params[:body].length
|
||||||
|
@ -51,13 +49,12 @@ module Fog
|
||||||
response = AWS::Response.new
|
response = AWS::Response.new
|
||||||
response.status = @connection.readline[9..11].to_i
|
response.status = @connection.readline[9..11].to_i
|
||||||
while true
|
while true
|
||||||
data = @connection.readline
|
data = @connection.readline[0..-3]
|
||||||
if data == "\r\n"
|
if data == ""
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
if header = data.match(/(.*):\s(.*)\r\n/)
|
header = data.split(': ')
|
||||||
response.headers[header[1]] = header[2]
|
response.headers[header[0]] = header[1]
|
||||||
end
|
|
||||||
end
|
end
|
||||||
if response.headers['Content-Length']
|
if response.headers['Content-Length']
|
||||||
content_length = response.headers['Content-Length'].to_i
|
content_length = response.headers['Content-Length'].to_i
|
||||||
|
|
Loading…
Add table
Reference in a new issue