Skip to content

Instantly share code, notes, and snippets.

@justincampbell
Created August 2, 2012 20:59
Show Gist options
  • Save justincampbell/3240599 to your computer and use it in GitHub Desktop.
Save justincampbell/3240599 to your computer and use it in GitHub Desktop.
Socket.IO + Redis load test
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