Home > Software > ANN – Curb 0.3.1 magic multi release

ANN – Curb 0.3.1 magic multi release

March 19th, 2009

It’s been nearly 8 months, since I decided to add multi interface support to curb.  Now we have a new release on rubyforge (0.3.1)

The major changes includes:

  • Add multi interface support
  • Avoid blocking other ruby threads while in a easy perform
  • Add support for HTTP DELETE Requests
  • Add basic support for HTTP PUT Requests (not from a file)
  • Ruby 1.9.1 Support
  • Upgraded packaging and dependencies for build and package
  • Upgraded test harness to run stressing the libcurl http code base
  • Incorporated 8 months of testing and development through github contributors

The addition of Multi interface means it’s now possible to issue thousands of request simultaneously with a single ruby thread.

To highlight the added support of the Multi interface here is an example that makes 5 requests to some major sites in parallel.

require 'rubygems'
require 'curb'
responses = {}
requests = ["http://www.google.com/",
            "http://www.yahoo.com/",
            "http://www.ebay.com/",
            "http://www.amazon.com/",
            "http://www.msn.com/",
            "http://www.google.co.uk/",
            "http://www.ruby-lang.org/"]
m = Curl::Multi.new
# add a few easy handles
requests.each do |url|
  responses[url] = ""
  c = Curl::Easy.new(url) do|curl|
    curl.follow_location = true
    curl.on_body{|data| responses[url] << data; data.size }
    curl.on_complete{|cl| puts "done #{curl.last_effective_url}" }
  end
  m.add(c)
end
idle_count = 0
m.perform do
  idle_count += 1
end

requests.each do|url|
  puts "#{url} responded with #{responses[url].size} bytes"
end
puts "idled: #{idle_count} times"

To install:

gem install curb

Enjoy!

Update:

Removed a GC.start inside the perform loop, was only there to verify objects were being correctly collected e.g. testing purposes.

Software ,

  1. March 31st, 2009 at 10:36 | #1

    GC.start in the perform loop? Any reason for that?

    Ilyas last blog post..Ruby Algorithms: Sorting, Trie & Heaps

  2. March 31st, 2009 at 11:49 | #2

    Ah, I had that in there for testing. I’ve updated the post and removed it. Thanks for the catch!

  3. Gerhard
    June 13th, 2009 at 09:46 | #3

    Hello,
    first thanks for Curb!
    My problem: Could you implement a Curl::Err exeption code for libcurl’s exit code 78 (“The resource referenced in the URL does not exist.”)? ATM if i fetch a ressource which not exist on remote server i got only the default Curl::Err::CurlError(Unknown error result from libcurl). From all new exist codes in current libcur version this is IMHO the most important, so a own exeption would help much.
    I looked at curb_errors.c/h, but I’m not familar with C.
    If you have a patch (for testing) or put it in git, this would be nice!

  4. June 13th, 2009 at 11:36 | #4

    Hi Gerhard,
    I’ve updated added the additional error codes to curb. You can see the changes here: http://github.com/taf2/curb/commit/d953fe3caeae66b7bbe055fa79008ca379327576

  5. Gerhard
    June 14th, 2009 at 06:56 | #5

    @taf2
    Works fine. Thank you!

  6. June 24th, 2009 at 18:09 | #6

    Any plans for a 0.4.x release to rubyforge to include the ‘big file uploads’ ?

  7. June 25th, 2009 at 09:47 | #7

    Yes, should be this week

  1. No trackbacks yet.
CommentLuv Enabled

Comments links could be nofollow free.