karmi/tire — Issue #166: Shellouts performance
Author: ifesdjeen
Created: 2011-12-10 18:11:23+00:00
State: open

I noticed today that Tire is using curl shellouts for accessing API.

Shellouts are generally very expensive. Here are some very basic benchmarks:

shelled-out CURL

1000.times do
`curl -X GET "http://google.com" -d '#{ { :a => 1 }}'`
end
# ruby test_curl.rb 5.69s user 3.98s system 17% cpu 53.908 total

faraday:

require 'faraday'

1000.times do
a = Faraday.new('http://google.com') do |b| b.adapter :net_http end
puts a.get('/')
end
# ruby test_faraday.rb 0.95s user 0.30s system 2% cpu 44.081 total

curb (curl ruby wrapper)
require 'curb'

1000.times do
Curl::Easy.perform("http://www.google.com")
end
# ruby test_curb.rb 0.43s user 0.35s system 1% cpu 47.704 total

It's not only taking a lot of time, it's also blocking execution of other threads, disallowing scheduler to use processor time for more useful things.

Do you guys have any interest to switch to faraday or curb? I could help out with that chore.