2014-02-19 44 views
2

我使用Ruby 1.9.3在本地主機上運行一個簡單的goliath服務器,它不是異步運行http請求。下面的代碼:Goliath不是異步的

require 'goliath' 
require 'em-synchrony' 
require 'em-synchrony/em-http' 

class Server < Goliath::API 
    use Goliath::Rack::Validation::RequestMethod, %w(GET PUT POST) 

    def initialize 
    super 
    puts "Started up Bookcover server... Let 'em come!" 
    end 

    def response(env) 
    thumbnail_cover_url, large_book_cover_url = ["http://riffle-bookcovers.s3.amazonaws.com/B00GJYXA5I-thumbnail.jpg", "http://riffle-bookcovers.s3.amazonaws.com/B00GJYXA5I-original.jpg"] 
    puts "start" 
    a = EM::HttpRequest.new(thumbnail_cover_url).get 
    b = EM::HttpRequest.new(large_book_cover_url).get 
    puts "done" 
    [200, {}, "Hello World"] 
    end 
end 

當我運行ab -n 100 http://127.0.0.1:9000/我可以看到它等待每個請求完成,這意味着呼叫阻塞。

但是,根據文獻Goliath使用Em-synchrony讓我編寫「同步外觀」的代碼,這裏不是這種情況。

我會很感激任何提示和意見!

回答

0

積分去igrigorik爲答案。我引用他的回答here

您還需要在運行ab ...時指定併發級別。 ab -c 10 :)

此外,請確保您在生產模式下運行它(-e prod)。