Skip to content

Instantly share code, notes, and snippets.

@frsyuki
Created July 13, 2010 08:23
Show Gist options
  • Save frsyuki/473627 to your computer and use it in GitHub Desktop.
Save frsyuki/473627 to your computer and use it in GitHub Desktop.
rev-websocket 5,000-connection benchmark
require 'rubygems'
require 'rev'
$LOAD_PATH << File.join(File.dirname(__FILE__),'lib')
require 'rev/websocket'
$connections = {}
class MyConnection < Rev::WebSocket
def on_open
$connections[self] = nil
end
def on_message(data)
$connections.each_key {|c|
c.send_message(data)
}
end
def on_close
$connections.delete(self)
end
end
host = '0.0.0.0'
port = '8080'
lo = Rev::Loop.default
server = Rev::WebSocketServer.new(host, port, MyConnection)
server.attach(lo)
timer = Rev::TimerWatcher.new(0.5, true)
timer.on_timer do
puts "#connections: #{$connections.size}"
end
timer.attach(lo)
lo.run
####
## Run server:
##
# $ sudo su -
# # ulimit -n 8192 # increases fd limit
# # su - frsyuki
# $ ruby example.rb
####
## Run clinet (benchmark tool):
##
# $ sudo su -
# # ulimit -n 8192 # increases fd limit
# # su - frsyuki
# $ ruby wsbench.rb ws://localhost:8080/ -c 8000 -T broadcast -t 60
# ["ws://localhost:8080/"]
# #<OpenStruct timeout=60.0, test_type="broadcast", message=1, connections=8000>
# "Epoll configured with only 8192 file descriptors"
# "0 connections, 0 messages"
# "0 connections, 0 messages"
# "0 connections, 0 messages"
# "1013 connections, 0 messages"
# "1823 connections, 0 messages"
# ...
# "received {\"data\":\"a\",\"start_time\":1279010137.94181,\"connection_id\":8000}"
# "received {\"data\":\"a\",\"start_time\":1279010137.94181,\"connection_id\":8000}"
# "8000 connections, 8000 messages"
# SUCCESS (8000/8000), Connect: sum 37148.307, max 5.854, min 1.268, avg 4.644 ,Message: sum 15061.199, max 2.421, min 1.189, avg 1.883, Total 14.700
####
## Environment
##
# - CPU: Athlon64 X2 5000+
# - Memory: DDR2 8GB
# - Linux vcore 2.6.27.10-server-1mnb #1 SMP Thu Jan 29 11:25:26 EST 2009 x86_64 AMD Athlon(tm) 64 X2 Dual Core Processor 5000+ GNU/Linux
# - ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]
# - rev-0.3.2
# - eventmachine-0.12.10
# - rev-websocket-0.1.0
# - wsbench.rb http://github.com/makoto/wsbench 3bd48b46de9a9df4b5318d86331432931bb79b32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment