Skip to content

Instantly share code, notes, and snippets.

@rehanift
Last active August 29, 2015 14:01
Show Gist options
  • Save rehanift/edf6beff3a149ffe4e0a to your computer and use it in GitHub Desktop.
Save rehanift/edf6beff3a149ffe4e0a to your computer and use it in GitHub Desktop.
var zmq = require("zmq");
var node_uuid = require('node-uuid');
var arrayUnique = function(a) {
return a.reduce(function(p, c) {
if (p.indexOf(c) < 0) p.push(c);
return p;
}, []);
};
var pubSubPort = "tcp://127.0.0.1:55555";
var subCount = 2500;
var subscriptions = [];
for (var s = 0; s < subCount; s++) {
subscriptions.push((node_uuid().split("-"))[0]);
}
console.log("unique subscriptions:"+(arrayUnique(subscriptions)).length);
// create a subscription with all generated filters (ie. 2500)
var subSocket = zmq.socket('sub');
subSocket.connect(pubSubPort);
for (var i = 0; i < subCount; i++) {
subSocket.subscribe(subscriptions[i]);
}
var done = 0;
subSocket.on("message", function(data){
done++;
console.log(done);
var message = data.toString();
var filter = message.split(" ")[0];
subSocket.unsubscribe(filter);
});
var pubSocket = zmq.socket('pub');
pubSocket.bind(pubSubPort, function(err){
console.log("socket bound");
setTimeout(function(){
for (var j = 0; j < subCount; j++) {
pubSocket.send(subscriptions[j]+" hello");
}
console.log("messages sent");
}, 5000);
});
var zmq = require("zmq");
var arrayUnique = function(a) {
return a.reduce(function(p, c) {
if (p.indexOf(c) < 0) p.push(c);
return p;
}, []);
};
var pubSubPort = "tcp://127.0.0.1:55555";
var subCount = 2500;
var subscriptions = [];
for (var s = 0; s < subCount; s++) {
subscriptions.push("abcdefghijklmnopqrstuvwxyz"+s);
}
console.log("unique subscriptions:"+(arrayUnique(subscriptions)).length);
// create a subscription with all generated filters (ie. 2500)
var subSocket = zmq.socket('sub');
subSocket.connect(pubSubPort);
for (var i = 0; i < subCount; i++) {
subSocket.subscribe(subscriptions[i]);
}
var done = 0;
subSocket.on("message", function(data){
done++;
console.log(done);
var message = data.toString();
var filter = message.split(" ")[0];
subSocket.unsubscribe(filter);
});
var pubSocket = zmq.socket('pub');
pubSocket.bind(pubSubPort, function(err){
console.log("socket bound");
setTimeout(function(){
for (var j = 0; j < subCount; j++) {
pubSocket.send(subscriptions[j]+" hello");
}
console.log("messages sent");
}, 5000);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment