Skip to content
Browse files

Addressed some issues with the perf tests and added documentation.

  • Loading branch information...
1 parent a42d36b commit c498ad7c01bcb06d4d6898cc641ff258a598b26b @ronkorving ronkorving committed Jul 17, 2013
Showing with 60 additions and 14 deletions.
  1. +34 −0 README.md
  2. +11 −9 perf/remote_lat.js
  3. +15 −5 perf/remote_thr.js
View
34 README.md
@@ -55,3 +55,37 @@ sock.on('message', function(msg){
Test:
$ make test
+
+## Running benchmarks
+
+Benchmarks are available in the `perf` directory, and have been implemented
+according to the zmq documentation:
+[How to run performance tests](http://www.zeromq.org/results:perf-howto)
+
+In the following examples, the arguments are respectively:
+- the host to connect to/bind on
+- message size (in bytes)
+- message count
+
+You can run a latency benchmark by running these two commands in two separate
+shells:
+
+```sh
+node ./local_lat.js tcp://127.0.0.1:5555 1 100000
+```
+
+```sh
+node ./remote_lat.js tcp://127.0.0.1:5555 1 100000
+```
+
+And you can run throughput tests by running these two commands in two
+separate shells:
+
+```sh
+node ./local_thr.js tcp://127.0.0.1:5555 1 100000
+```
+
+```sh
+node ./remote_thr.js tcp://127.0.0.1:5555 1 100000
+```
+
View
20 perf/remote_lat.js
@@ -12,7 +12,7 @@ var roundtrip_count = Number(process.argv[4])
var message = new Buffer(message_size)
message.fill('h')
-var sendCounter = recvCounter = 0
+var recvCounter = 0
var req = zmq.socket('req')
req.connect(connect_to)
@@ -21,24 +21,26 @@ 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()
+ if (++recvCounter === roundtrip_count) {
+ finish()
+ } else {
+ send()
+ }
})
function finish(){
- var endtime = process.hrtime(timer)
- var millis = (endtime[0]*1000) + (endtime[1]/1000000)
+ 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', endtime[0], endtime[1])
+ console.log('overall time: %d secs and %d nanoseconds', duration[0], duration[1])
req.close()
}
function send(){
- process.nextTick(function () {
- req.send(message)
- if (++sendCounter < roundtrip_count) send()
- })
+ req.send(message)
}
+
send()
View
20 perf/remote_thr.js
@@ -12,8 +12,6 @@ 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')
@@ -22,8 +20,20 @@ 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
+
+ if (++counter < message_count)
+ send()
+ else
+ // all messages may not be received by local_thr if closed immediately
+ setTimeout(function () {
+ pub.close()
+ }, 1000);
})
}
-send()
+
+// because of what seems to be a bug in node-zmq, we would lose messages
+// if we start sending immediately after calling connect(), so to make this
+// benchmark behave well, we wait a bit...
+
+setTimeout(send, 1000);
+

0 comments on commit c498ad7

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