Skip to content

Instantly share code, notes, and snippets.

@nikushi
Created April 30, 2012 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikushi/2559791 to your computer and use it in GitHub Desktop.
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!
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