Created
April 13, 2011 18:02
-
-
Save nathanwdavis/918029 to your computer and use it in GitHub Desktop.
a more refined version of https://gist.github.com/907514 - a test for publish speed of zeromq in nodejs
This file contains 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
var cnt, mes, s, sender, util, zmq, ms; | |
ms = 1000; | |
zmq = require('zeromq'); | |
util = require('util'); | |
s = zmq.createSocket('pub'); | |
s.bind('tcp://127.0.0.1:5559', function(err) { | |
if (err) { | |
throw err; | |
} | |
util.puts('binding'); | |
}); | |
cnt = 1; | |
mes = function() { | |
var data; | |
data = "" + cnt; | |
if (cnt % 100 === 0) { | |
util.puts("sending " + data); | |
} | |
s.send(data); | |
cnt++; | |
}; | |
process.on('SIGINT', function() { | |
clearInterval(sender); | |
s.close(); | |
console.log("Quitting now"); | |
process.exit(1); | |
}); | |
util.puts('Ready to go!'); | |
sender = setInterval(mes, 0); | |
setTimeout(function() { | |
util.puts('Sent '+ cnt +' in '+ ms +' milliseconds'); | |
process.kill(process.pid, 'SIGINT'); | |
}, ms); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment