2

I am running a simple goliath server on my localhost with Ruby 1.9.3, and it's not running http requests asynchronously. Here's the code:

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

When I run ab -n 100 http://127.0.0.1:9000/ I can see it waits for each request to be done, which means that the calls are blocking.

However, according to the documentation Goliath uses Em-synchrony to let me write "synchronous-looking" code, which is not the case here.

I would appreciate any hints and comments!

Kenny Meyer
  • 7,849
  • 6
  • 45
  • 66

1 Answers1

0

Credits go to igrigorik for the answer. I quote from his answer here:

You also need to specify the concurrency level when you run ab... e.g. ab -c 10 :)

Also, make sure you run it in production mode (-e prod).

Community
  • 1
  • 1
Kenny Meyer
  • 7,849
  • 6
  • 45
  • 66