Permalink
Browse files

Changed: pub/sub for perf is now push/pull.

Fixed: latency formula was flawed (showing 4x slower latency than reality).
Fixed: nextTick recursion.
Fixed: stylistic cleanups.
  • Loading branch information...
1 parent c498ad7 commit 6f6c8ff9a1e4a7423fc9304ef46ad7143592a585 @ronkorving ronkorving committed Jul 25, 2013
Showing with 86 additions and 78 deletions.
  1. +13 −13 perf/local_lat.js
  2. +30 −26 perf/local_thr.js
  3. +32 −26 perf/remote_lat.js
  4. +11 −13 perf/remote_thr.js
View
@@ -1,21 +1,21 @@
-var zmq = require('../')
-var assert = require('assert')
+var zmq = require('../');
+var assert = require('assert');
if (process.argv.length != 5) {
- console.log('usage: local_lat <bind-to> <message-size> <roundtrip-count>')
- process.exit(1)
+ console.log('usage: local_lat <bind-to> <message-size> <roundtrip-count>');
+ process.exit(1);
}
-var bind_to = process.argv[2]
-var message_size = Number(process.argv[3])
-var roundtrip_count = Number(process.argv[4])
-var counter = 0
+var bind_to = process.argv[2];
+var message_size = Number(process.argv[3]);
+var roundtrip_count = Number(process.argv[4]);
+var counter = 0;
-var rep = zmq.socket('rep')
-rep.bindSync(bind_to)
+var rep = zmq.socket('rep');
+rep.bindSync(bind_to);
rep.on('message', function (data) {
- assert.equal(data.length, message_size, 'message-size did not match')
- rep.send(data)
- if (++counter === roundtrip_count) rep.close()
+ assert.equal(data.length, message_size, 'message-size did not match');
+ rep.send(data);
+ if (++counter === roundtrip_count) rep.close();
})
View
@@ -1,37 +1,41 @@
-var zmq = require('../')
-var assert = require('assert')
+var zmq = require('../');
+var assert = require('assert');
if (process.argv.length != 5) {
- console.log('usage: local_thr <bind-to> <message-size> <message-count>')
- process.exit(1)
+ console.log('usage: local_thr <bind-to> <message-size> <message-count>');
+ process.exit(1);
}
-var bind_to = process.argv[2]
-var message_size = Number(process.argv[3])
-var message_count = Number(process.argv[4])
-var counter = 0
+var bind_to = process.argv[2];
+var message_size = Number(process.argv[3]);
+var message_count = Number(process.argv[4]);
+var counter = 0;
-var sub = zmq.socket('sub')
-sub.bindSync(bind_to)
-sub.subscribe('')
+var sock = zmq.socket('pull');
+sock.bindSync(bind_to);
-var timer = process.hrtime()
+var timer;
-sub.on('message', function (data) {
- assert.equal(data.length, message_size, 'message-size did not match')
- if (++counter === message_count) finish()
+sock.on('message', function (data) {
+ if (!timer) {
+ console.log('started receiving');
+ timer = process.hrtime();
+ }
+
+ assert.equal(data.length, message_size, 'message-size did not match');
+ if (++counter === message_count) finish();
})
function finish(){
- var endtime = process.hrtime(timer)
- var millis = (endtime[0]*1000) + (endtime[1]/1000000)
- var throughput = message_count / (millis / 1000)
- var megabits = (throughput * message_size * 8) / 1000000
-
- console.log('message size: %d [B]', message_size)
- console.log('message count: %d', message_count)
- console.log('mean throughput: %d [msg/s]', throughput.toFixed(0))
- console.log('mean throughput: %d [Mbit/s]', megabits.toFixed(0))
- console.log('overall time: %d secs and %d nanoseconds', endtime[0], endtime[1])
- sub.close()
+ var endtime = process.hrtime(timer);
+ var sec = endtime[0] + (endtime[1]/1000000000);
+ var throughput = message_count / sec;
+ var megabits = (throughput * message_size * 8) / 1000000;
+
+ console.log('message size: %d [B]', message_size);
+ console.log('message count: %d', message_count);
+ console.log('mean throughput: %d [msg/s]', throughput.toFixed(0));
+ console.log('mean throughput: %d [Mbit/s]', megabits.toFixed(0));
+ console.log('overall time: %d secs and %d nanoseconds', endtime[0], endtime[1]);
+ sock.close();
}
View
@@ -1,46 +1,52 @@
-var zmq = require('../')
-var assert = require('assert')
+var zmq = require('../');
+var assert = require('assert');
if (process.argv.length != 5) {
- console.log('usage: remote_lat <connect-to> <message-size> <roundtrip-count>')
- process.exit(1)
+ console.log('usage: remote_lat <connect-to> <message-size> <roundtrip-count>');
+ process.exit(1);
}
-var connect_to = process.argv[2]
-var message_size = Number(process.argv[3])
-var roundtrip_count = Number(process.argv[4])
-var message = new Buffer(message_size)
-message.fill('h')
+var connect_to = process.argv[2];
+var message_size = Number(process.argv[3]);
+var roundtrip_count = Number(process.argv[4]);
+var message = new Buffer(message_size);
+message.fill('h');
-var recvCounter = 0
+var recvCounter = 0;
-var req = zmq.socket('req')
-req.connect(connect_to)
+var req = zmq.socket('req');
+req.connect(connect_to);
-var timer = process.hrtime()
+var timer;
req.on('message', function (data) {
- assert.equal(data.length, message_size, 'message-size did not match')
+ if (!timer) {
+ console.log('started receiving');
+ timer = process.hrtime();
+ }
+
+ assert.equal(data.length, message_size, 'message-size did not match');
+
if (++recvCounter === roundtrip_count) {
- finish()
+ finish();
} else {
- send()
+ send();
}
-})
+});
-function finish(){
- var duration = process.hrtime(timer)
- var millis = (duration[0]*1000) + (duration[1]/1000000)
+function finish() {
+ var duration = process.hrtime(timer);
+ var millis = duration[0] * 1000 + duration[1] / 1000000;
- console.log('message size: %d [B]', message_size)
- console.log('roundtrip count: %d', roundtrip_count)
- console.log('mean latency: %d [msecs]', millis / roundtrip_count * 2)
- console.log('overall time: %d secs and %d nanoseconds', duration[0], duration[1])
+ console.log('message size: %d [B]', message_size);
+ console.log('roundtrip count: %d', roundtrip_count);
+ console.log('mean latency: %d [msecs]', millis / (roundtrip_count * 2));
+ console.log('overall time: %d secs and %d nanoseconds', duration[0], duration[1]);
req.close()
}
-function send(){
- req.send(message)
+function send() {
+ req.send(message);
}
send()
View
@@ -14,21 +14,19 @@ message.fill('h')
var counter = 0
-var pub = zmq.socket('pub')
-pub.connect(connect_to)
+var sock = zmq.socket('push')
+//sock.setsockopt(zmq.ZMQ_SNDHWM, message_count);
+sock.connect(connect_to)
function send(){
- process.nextTick(function () {
- pub.send(message)
-
- if (++counter < message_count)
- send()
- else
- // all messages may not be received by local_thr if closed immediately
- setTimeout(function () {
- pub.close()
- }, 1000);
- })
+ for (var i = 0; i < message_count; i++) {
+ sock.send(message)
+ }
+
+ // all messages may not be received by local_thr if closed immediately
+ setTimeout(function () {
+ sock.close()
+ }, 1000);
}
// because of what seems to be a bug in node-zmq, we would lose messages

0 comments on commit 6f6c8ff

Please sign in to comment.