wrk2
wrk2 copied to clipboard
Number of created connections sometimes is greater by 1 than specified at command line
Testing code (NodeJS 6)
const express = require('express');
const logger = require('log4js').getLogger();
const uid = require('uid');
const assert = require('assert');
var app = express();
var reqCnt = {};
app.get('/', (req,res)=>{
logger.debug(`Request, socket id=${req.connection.uid}`);
assert.notEqual(reqCnt[req.connection.uid], undefined);
reqCnt[req.connection.uid]++;
res.send('ok');
});
setInterval( ()=>{
var uids = Object.keys(reqCnt);
//logger.debug(`Connection number: ${uids.length}`);
for ( var uid of uids ) {
//logger.debug(`${uid}: ${reqCnt[uid]} req/s`);
reqCnt[uid] = 0;
}
}, 1000);
var httpSrv = app.listen(8080);
httpSrv
.on('connection', function(socket) {
socket.uid = uid();
reqCnt[socket.uid] = 0; // zero requests on that connection
logger.debug(`connection is established: id=${socket.uid}, local: ${socket.localAddress}:${socket.localPort}, remote: ${socket.remoteAddress}:${socket.remotePort}`);
logger.debug(socket.address());
socket
.on('data', function(data) {
//logger.debug(`id=${socket.uid}, Data: unshown`);
})
.on('timeout', function() {
logger.debug(`socket timeout: local: ${socket.localAddress}:${socket.localPort}, remote: ${socket.remoteAddress}:${socket.remotePort}`);
})
.on('close', function() {
//console.log(socket);
logger.debug(`socket closed: id=${socket.uid}, local: ${socket.localAddress}:${socket.localPort}, remote: ${socket.remoteAddress}:${socket.remotePort}`);
});
});
Running wrk2 with
./wrk -d 10 -t 2 -c 8 -R 20 http://localhost:8080
Output of
> node server.js | grep established
morpher@morpher-Inspiron-5447 ~/Documents/test_sockets $ node server.js | grep established
[2016-08-22 09:57:14.123] [DEBUG] [default] - connection is established: id=wrpb37o, local: ::ffff:127.0.0.1:8080, remote: ::ffff:127.0.0.1:44399
[2016-08-22 09:57:14.161] [DEBUG] [default] - connection is established: id=wdy8o3m, local: ::ffff:127.0.0.1:8080, remote: ::ffff:127.0.0.1:44400
[2016-08-22 09:57:14.162] [DEBUG] [default] - connection is established: id=i5tqom2, local: ::ffff:127.0.0.1:8080, remote: ::ffff:127.0.0.1:44401
[2016-08-22 09:57:14.162] [DEBUG] [default] - connection is established: id=eedh7a2, local: ::ffff:127.0.0.1:8080, remote: ::ffff:127.0.0.1:44402
[2016-08-22 09:57:14.163] [DEBUG] [default] - connection is established: id=op3an49, local: ::ffff:127.0.0.1:8080, remote: ::ffff:127.0.0.1:44403
[2016-08-22 09:57:14.163] [DEBUG] [default] - connection is established: id=h1o8a37, local: ::ffff:127.0.0.1:8080, remote: ::ffff:127.0.0.1:44404
[2016-08-22 09:57:14.163] [DEBUG] [default] - connection is established: id=sqr6t8d, local: ::ffff:127.0.0.1:8080, remote: ::ffff:127.0.0.1:44405
[2016-08-22 09:57:14.164] [DEBUG] [default] - connection is established: id=unk79u6, local: ::ffff:127.0.0.1:8080, remote: ::ffff:127.0.0.1:44406
[2016-08-22 09:57:14.164] [DEBUG] [default] - connection is established: id=m7g0l5b, local: ::ffff:127.0.0.1:8080, remote: ::ffff:127.0.0.1:44407
There are 9 connections although I specified 8 connections. Currently switched to apache benchmarking (ab) - it passes the test successfully.
It is 0 indexed I think... yet the command line refuses 1o take 0 connections.. so I don't know..
My basis for this statement is "Step 4 — Run a wrk Benchmark Test" of the following article
https://www.digitalocean.com/community/tutorials/how-to-benchmark-http-latency-with-wrk-on-ubuntu-14-04
If that is indeed so, it is too bad the README and help text does not clarify/confirm it. Does one have to look through the source code to figure that out. The usage wording is counter to that blog post.