I’m trying to understand how to use various non-blocking IO libraries in Ruby and made a simple app for testing using Sinatra,
# proxy.rb
require 'bundler/setup'
require 'sinatra/base'
require 'sinatra/synchrony'
require 'faraday'
class ProxyApp < Sinatra::Base
register Sinatra::Synchrony
get "/proxy" do
conn = Faraday.new("http://mirror.yandex.ru") do |faraday|
faraday.use Faraday::Adapter::EMSynchrony
end
conn.get "/ubuntu-releases/precise/ubuntu-12.04.1-alternate-i386.iso"
"Hello, world"
end
get "/" do
"Hello, world"
end
end
As far as I understand, downloading a file using non-blocking IO should allow other requests to execute, but it doesn’t – if I’m using ab to open /proxy path (I’m using Thin as an app server), request to / takes a very long time. Am I doing something wrong?
Sinatra::Synchrony? Why?
config.ru:
Gemfile:
proxy.rb:
Start:
In another terminal:
The reply is immediate for /, no matter how many requests to /proxy you do in parrallel.