#!/usr/bin/env ruby # Example benchmark scripts: # # websocket-bench broadcast ws://127.0.0.1:3000/ --concurrent 10 --sample-size 100 --server-type binary --step-size 1000 --limit-percentile 95 --limit-rtt 250ms --initial-clients 1000 # # websocket-bench broadcast ws://127.0.0.1:3000/ --concurrent 10 --sample-size 100 --step-size 1000 --limit-percentile 95 --limit-rtt 250ms --initial-clients 1000 --server-type json # Dir.chdir(File.expand_path(File.join('..', '..', 'lib'), __FILE__)) require 'bundler/setup' require 'plezi' class ShootoutApp CHANNEL = "shootout".freeze # the default HTTP response def index "This application should be used with the websocket-shootout benchmark utility." end def on_open subscribe CHANNEL end # we won't be using AutoDispatch, but directly using the `on_message` callback. def on_message data if data[0] == 'b' # binary publish(CHANNEL, data) data[0] = 'r' write data return end cmd, payload = JSON(data).values_at('type', 'payload') if cmd == 'echo' write({type: 'echo', payload: payload}.to_json) else publish(CHANNEL, ({type: 'broadcast', payload: payload}.to_json)) write({type: "broadcastResult", payload: payload}.to_json) end rescue puts "Incoming message format error - not JSON?" end end Plezi.route '*', ShootoutApp # # def cycle # puts `websocket-bench broadcast ws://127.0.0.1:3000/ --concurrent 10 --sample-size 100 --server-type binary --step-size 1000 --limit-percentile 95 --limit-rtt 250ms --initial-clients 1000` # sleep(2) # puts `wrk -c4000 -d15 -t12 http://localhost:3000/` # true # end # sleep(10) while cycle