Skip to content

Instantly share code, notes, and snippets.

@boosty
Created June 16, 2011 21:39
Show Gist options
  • Save boosty/1030354 to your computer and use it in GitHub Desktop.
Save boosty/1030354 to your computer and use it in GitHub Desktop.
Non-blocking system call using goliath
source "http://rubygems.org"
gem "goliath"
require "rubygems"
require "bundler/setup"
require "goliath"
class LongRunningSystemCall < Goliath::API
def response(env)
fiber = Fiber.current
EM.system('sleep 5') do |output,status|
fiber.resume
end
Fiber.yield
[200, {}, "Hello world"]
end
end
# Use ruby 1.9.2!
#
# ruby long_running_system_call.rb -e prod
#
# ab -c100 -n100 http://127.0.0.1:9000/
# Concurrency Level: 100
# Time taken for tests: 5.657 seconds !!!
# Complete requests: 100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment