Created
June 16, 2011 21:39
-
-
Save boosty/1030354 to your computer and use it in GitHub Desktop.
Non-blocking system call using goliath
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "http://rubygems.org" | |
gem "goliath" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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