Created
August 2, 2012 20:59
-
-
Save justincampbell/3240599 to your computer and use it in GitHub Desktop.
Socket.IO + Redis load test
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
redis = require("redis").createClient() | |
io = require("socket.io-client") | |
RESULT_COUNT = process.argv[2] | |
DATA_LENGTH = process.argv[3] | |
channel = "channel#{Math.floor(Math.random() * 1024)}" | |
results = [] | |
console.log channel | |
socket = io.connect ":4000" | |
socket.on "connect", -> | |
socket.emit "subscribe", channel | |
socket.on channel, (data) -> | |
results.push data | |
setTimeout -> | |
console.log "publishing" | |
for number in [1..RESULT_COUNT] | |
redis.publish channel, reusableRandomString | |
console.log "done" | |
, 1000 | |
setTimeout -> | |
console.log "#{results.length} responses, expected #{RESULT_COUNT}" | |
, 2000 | |
setTimeout -> | |
console.log "#{results.length} responses, expected #{RESULT_COUNT}" | |
, 5000 | |
setTimeout -> | |
console.log "#{results.length} responses, expected #{RESULT_COUNT}" | |
process.exit() | |
, 10000 | |
randomString = (size) -> | |
characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-' | |
result = '' | |
for number in [1..size] | |
rand = Math.floor(Math.random() * characters.length) | |
result += characters[rand] | |
return result | |
reusableRandomString = randomString(DATA_LENGTH) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment