Skip to content
Browse files

Merge pull request #138 from wavded/perf

added; local/remote_lat local/remote_thr perf test
  • Loading branch information...
2 parents a753448 + 1e4ee4d commit 8d5bc8bdb583ab7677b80299a892a768de35e8b5 @ronkorving ronkorving committed Feb 14, 2013
Showing with 131 additions and 0 deletions.
  1. +21 −0 perf/local_lat.js
  2. +37 −0 perf/local_thr.js
  3. +44 −0 perf/remote_lat.js
  4. +29 −0 perf/remote_thr.js
View
21 perf/local_lat.js
@@ -0,0 +1,21 @@
+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)
+}
+
+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)
+
+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()
+})
View
37 perf/local_thr.js
@@ -0,0 +1,37 @@
+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)
+}
+
+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 timer = process.hrtime()
+
+sub.on('message', function (data) {
+ 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/1000000)
+ 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 [Mb/s]', megabits.toFixed(0))
+ console.log('overall time: %d secs and %d nanoseconds', endtime[0], endtime[1])
+ sub.close()
+}
View
44 perf/remote_lat.js
@@ -0,0 +1,44 @@
+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)
+}
+
+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 sendCounter = recvCounter = 0
+
+var req = zmq.socket('req')
+req.connect(connect_to)
+
+var timer = process.hrtime()
+
+req.on('message', function (data) {
+ assert.equal(data.length, message_size, 'message-size did not match')
+ if (++recvCounter === roundtrip_count) finish()
+})
+
+function finish(){
+ var endtime = process.hrtime(timer)
+ var millis = (endtime[0]*1000) + (endtime[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', endtime[0], endtime[1])
+ req.close()
+}
+
+function send(){
+ process.nextTick(function () {
+ req.send(message)
+ if (++sendCounter < roundtrip_count) send()
+ })
+}
+send()
View
29 perf/remote_thr.js
@@ -0,0 +1,29 @@
+var zmq = require('../')
+var assert = require('assert')
+
+if (process.argv.length != 5) {
+ console.log('usage: remote_thr <bind-to> <message-size> <message-count>')
+ process.exit(1)
+}
+
+var connect_to = process.argv[2]
+var message_size = Number(process.argv[3])
+var message_count = Number(process.argv[4])
+var message = new Buffer(message_size)
+message.fill('h')
+
+console.log(message.length)
+
+var counter = 0
+
+var pub = zmq.socket('pub')
+pub.connect(connect_to)
+
+function send(){
+ process.nextTick(function () {
+ pub.send(message)
+ if (++counter < message_count) send()
+ // else pub.close() // all messages may not be received by local_thr if closed
+ })
+}
+send()

0 comments on commit 8d5bc8b

Please sign in to comment.
Something went wrong with that request. Please try again.