Last active
August 29, 2015 14:01
-
-
Save rehanift/edf6beff3a149ffe4e0a to your computer and use it in GitHub Desktop.
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 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); | |
}); |
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 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