Skip to content

Commit

Permalink
Merge branch 'master' of github.com:taf2/curb
Browse files Browse the repository at this point in the history
  • Loading branch information
taf2 committed Nov 5, 2011
2 parents dba7d39 + 9b787a0 commit 440f9f8
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 25 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
0.7.16
* Add better support for timeouts issue 48
* Improve stablity, avoid bus errors when raising in callbacks
* Allow Content-Length header when sending a PUT request
* Better handling of cacert
Expand Down
3 changes: 2 additions & 1 deletion bench/Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
source :rubygems

gem 'curb', '0.1.4'
gem 'curb', '0.3.2'
gem 'rmem'
gem 'net-http-persistent'
gem 'em-http-request'
gem 'patron'
gem 'typhoeus'
gem 'rake'
6 changes: 4 additions & 2 deletions bench/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ GEM
remote: http://rubygems.org/
specs:
addressable (2.2.4)
curb (0.1.4)
curb (0.3.2)
em-http-request (0.3.0)
addressable (>= 2.0.0)
escape_utils
Expand All @@ -12,6 +12,7 @@ GEM
mime-types (1.16)
net-http-persistent (1.6.1)
patron (0.4.11)
rake (0.9.2)
rmem (1.0.0)
typhoeus (0.2.4)
mime-types
Expand All @@ -21,9 +22,10 @@ PLATFORMS
ruby

DEPENDENCIES
curb (= 0.1.4)
curb (= 0.3.2)
em-http-request
net-http-persistent
patron
rake
rmem
typhoeus
28 changes: 24 additions & 4 deletions bench/Rakefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
task :default do
sh "bundle install"
n = 200
[:curb_easy, :curb_easy14, :curb_multi, :curb_multi_using_get, :emhttprequest, :nethttp_test, :patron_test, :typhoeus_hydra_test, :typhoeus_test].each do|bench|
system "ruby #{bench}.rb #{n}"
sleep 1
n = 8000
results = {}
system("cd ../ && rake compile")
[:curb_easy14, :curb_easy, :curb_multi, :curb_multi_using_get, :emhttprequest, :nethttp_test, :patron_test, :typhoeus_hydra_test, :typhoeus_test].each do|bench|
result = `ruby #{bench}.rb #{n}`
results[bench] = result.scan(/Duration: (\d*\.\d*) sec, Memory Usage: (\d*\.\d*) KB - Memory Growth: (\d*\.\d*) KB/).flatten.map {|v| v.to_f}
results.delete(bench) if results[bench].empty?
puts result
end
# find shortest time
best_time = nil
best_key_time = nil
results.each do|k,v|
if best_time.nil? || best_time.first > v.first
best_key_time = k
best_time = v
end
end
puts "Fastest: #{best_key_time} in #{best_time.inspect}"

# find smallest memory
best_mem = nil
best_key_mem = nil
results.each do|k,v|
end
end
2 changes: 1 addition & 1 deletion bench/_usage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def self.usage(name)
memory_usage = emem / 1024.0
memory_growth = (emem - smem) / 1024.0

printf "#{name}\t\tDuration: %.4f sec, Memory Usage: %.2f KB - Memory Growth: %.2f KB\n", duration, memory_usage, memory_growth
printf "#{name}\t\tDuration: %.4f sec, Memory Usage: %.2f KB - Memory Growth: %.2f KB average: #{duration/N}\n", duration, memory_usage, memory_growth
end

end
3 changes: 2 additions & 1 deletion bench/curb_easy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
c = Curl::Easy.new

N.times do|n|
c.url = BURL
c.url = BURL + "?n=#{n}"
c.on_header {|d| d.size} # don't buffer
c.on_body {|d| d.size} # don't buffer
c.perform
end
Expand Down
3 changes: 2 additions & 1 deletion bench/curb_easy14.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
c = Curl::Easy.new

N.times do|n|
c.url = BURL
c.url = BURL + "?n=#{n}"
c.on_header {|d| d.size} # don't buffer
c.on_body {|d| d.size} # don't buffer
c.perform
end
Expand Down
6 changes: 4 additions & 2 deletions bench/curb_multi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

N = (ARGV.shift || 50).to_i
BURL = 'http://127.0.0.1/zeros-2k'
count = 0

Memory.usage("Curl::Multi(#{N})") do
Memory.usage("Curl::Multi.pipelined(#{N})") do
require 'curb'

count = 0
Expand All @@ -25,7 +26,8 @@

# initialize first 10
10.times do
easy = Curl::Easy.new(BURL)
easy = Curl::Easy.new(BURL + "?n=#{count}")
count+=1
easy.on_body {|d| bytes_received += d.size; d.size } # don't buffer
easy.on_complete do|c|
free << c
Expand Down
4 changes: 2 additions & 2 deletions bench/curb_multi_using_get.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
N = (ARGV.shift || 50).to_i
BURL = 'http://127.0.0.1/zeros-2k'
URLS = []
N.times do
URLS << BURL
N.times do|n|
URLS << BURL + "?n=#{n}"
end

Memory.usage("Curl::Multi.get(#{N})") do
Expand Down
3 changes: 1 addition & 2 deletions bench/nethttp_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
require 'net/http/persistent'

http = Net::HTTP::Persistent.new
uri = URI.parse BURL

N.times do |n|
http.request uri
http.request URI.parse(BURL+"?n=#{n}")
end

end
4 changes: 2 additions & 2 deletions bench/typhoeus_hydra_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
hydra = Typhoeus::Hydra.new
reqs = []

N.times do
req = Typhoeus::Request.new('http://127.0.0.1/zeros-2k')
N.times do |n|
req = Typhoeus::Request.new('http://127.0.0.1/zeros-2k' + "?n=#{n}")
reqs << req
hydra.queue req
end
Expand Down
4 changes: 2 additions & 2 deletions bench/typhoeus_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

require 'typhoeus'

N.times do
Typhoeus::Request.get('http://127.0.0.1/zeros-2k')
N.times do|n|
Typhoeus::Request.get('http://127.0.0.1/zeros-2k' + "?n=#{n}")
end

end
3 changes: 0 additions & 3 deletions ext/curb.c
Original file line number Diff line number Diff line change
Expand Up @@ -838,9 +838,6 @@ void Init_curb_core() {
#if HAVE_CURLOPT_SSLVERSION
CURB_DEFINE(CURLOPT_SSLVERSION);
#endif
#if HAVE_CURL_SSLVERSION_DEFAULT
CURB_DEFINE(CURL_SSLVERSION_DEFAULT);
#endif
#if HAVE_CURL_SSLVERSION_TLSv1
CURB_DEFINE(CURL_SSLVERSION_TLSv1);
#endif
Expand Down
2 changes: 2 additions & 0 deletions ext/curb_easy.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,13 @@ static int proc_debug_handler(CURL *curl,
char *data,
size_t data_len,
VALUE proc) {
VALUE procret;
VALUE callargs = rb_ary_new2(3);
rb_ary_store(callargs, 0, proc);
rb_ary_store(callargs, 1, INT2FIX(type));
rb_ary_store(callargs, 2, rb_str_new(data, data_len));
rb_rescue(call_debug_handler, callargs, callback_exception, Qnil);
// XXX: no way to indicate to libcurl that we should break out given an exception in the on_debug handler... this means exceptions will be swallowed
//rb_funcall(proc, idCall, 2, INT2FIX(type), rb_str_new(data, data_len));
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ def test_on_debug
c.on_progress do|x|
raise "error"
end
c.easy.on_debug { |type, data| puts "debug: #{type.inspect}, #{data.inspect}" }
c.perform

assert false, "should not reach this point"

rescue => e
assert_equal 'Curl::Err::AbortedByCallbackError', e.class.to_s
c.close
ensure
puts "shutdown server"
server.shutdown
end
end

0 comments on commit 440f9f8

Please sign in to comment.