Created
April 30, 2012 16:30
-
-
Save nikushi/2559791 to your computer and use it in GitHub Desktop.
A sample implementation of streaming server to make a lot concurrency connections. The connections are keepalived by server!
This file contains hidden or 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 'sinatra' | |
require 'eventmachine' | |
get '/' do | |
stream :keep_open do |out| | |
interval = 1 | |
size = 1000 | |
EventMachine::PeriodicTimer.new(interval) { out << "#{gen_data(size)}\n" } | |
end | |
end | |
post '/' do | |
'ok' | |
end | |
def gen_data(length=10) | |
chars = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ23456789' | |
Array.new(length) { chars[rand(chars.length)].chr }.join | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment