bench: fix up benchmarks after internal api change
This commit is contained in:
Родитель
e1fe8d4ec0
Коммит
d75f67f949
|
@ -2,6 +2,7 @@
|
|||
// as many bytes as we can in the specified time (default = 10s)
|
||||
|
||||
var common = require('../common.js');
|
||||
var util = require('util');
|
||||
|
||||
// if there are --dur=N and --len=N args, then
|
||||
// run the function with those settings.
|
||||
|
@ -27,26 +28,23 @@ function main(conf) {
|
|||
}
|
||||
|
||||
|
||||
function fail(syscall) {
|
||||
var e = new Error(syscall + ' ' + errno);
|
||||
e.errno = e.code = errno;
|
||||
e.syscall = syscall;
|
||||
throw e;
|
||||
function fail(err, syscall) {
|
||||
throw util._errnoException(err, syscall);
|
||||
}
|
||||
|
||||
function server() {
|
||||
var serverHandle = new TCP();
|
||||
var r = serverHandle.bind('127.0.0.1', PORT);
|
||||
if (r)
|
||||
fail('bind');
|
||||
var err = serverHandle.bind('127.0.0.1', PORT);
|
||||
if (err)
|
||||
fail(err, 'bind');
|
||||
|
||||
var r = serverHandle.listen(511);
|
||||
if (r)
|
||||
fail('listen');
|
||||
err = serverHandle.listen(511);
|
||||
if (err)
|
||||
fail(err, 'listen');
|
||||
|
||||
serverHandle.onconnection = function(clientHandle) {
|
||||
if (!clientHandle)
|
||||
fail('connect');
|
||||
serverHandle.onconnection = function(err, clientHandle) {
|
||||
if (err)
|
||||
fail(err, 'connect');
|
||||
|
||||
// the meat of the benchmark is right here:
|
||||
bench.start();
|
||||
|
@ -57,11 +55,11 @@ function server() {
|
|||
bench.end((bytes * 8) / (1024 * 1024 * 1024));
|
||||
}, dur * 1000);
|
||||
|
||||
clientHandle.onread = function(buffer) {
|
||||
clientHandle.onread = function(nread, buffer) {
|
||||
// we're not expecting to ever get an EOF from the client.
|
||||
// just lots of data forever.
|
||||
if (!buffer)
|
||||
fail('read');
|
||||
if (nread < 0)
|
||||
fail(nread, 'read');
|
||||
|
||||
// don't slice the buffer. the point of this is to isolate, not
|
||||
// simulate real traffic.
|
||||
|
@ -93,41 +91,44 @@ function client() {
|
|||
}
|
||||
|
||||
var clientHandle = new TCP();
|
||||
var connectReq = clientHandle.connect('127.0.0.1', PORT);
|
||||
var connectReq = {};
|
||||
var err = clientHandle.connect(connectReq, '127.0.0.1', PORT);
|
||||
|
||||
if (!connectReq)
|
||||
fail('connect');
|
||||
if (err)
|
||||
fail(err, 'connect');
|
||||
|
||||
clientHandle.readStart();
|
||||
|
||||
connectReq.oncomplete = function() {
|
||||
connectReq.oncomplete = function(err) {
|
||||
if (err)
|
||||
fail(err, 'connect');
|
||||
|
||||
while (clientHandle.writeQueueSize === 0)
|
||||
write();
|
||||
};
|
||||
|
||||
function write() {
|
||||
var writeReq
|
||||
var writeReq = { oncomplete: afterWrite };
|
||||
var err;
|
||||
switch (type) {
|
||||
case 'buf':
|
||||
writeReq = clientHandle.writeBuffer(chunk);
|
||||
err = clientHandle.writeBuffer(writeReq, chunk);
|
||||
break;
|
||||
case 'utf':
|
||||
writeReq = clientHandle.writeUtf8String(chunk);
|
||||
err = clientHandle.writeUtf8String(writeReq, chunk);
|
||||
break;
|
||||
case 'asc':
|
||||
writeReq = clientHandle.writeAsciiString(chunk);
|
||||
err = clientHandle.writeAsciiString(writeReq, chunk);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!writeReq)
|
||||
fail('write');
|
||||
|
||||
writeReq.oncomplete = afterWrite;
|
||||
if (err)
|
||||
fail(err, 'write');
|
||||
}
|
||||
|
||||
function afterWrite(status, handle, req) {
|
||||
if (status)
|
||||
fail('write');
|
||||
function afterWrite(err, handle, req) {
|
||||
if (err)
|
||||
fail(err, 'write');
|
||||
|
||||
while (clientHandle.writeQueueSize === 0)
|
||||
write();
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// as many bytes as we can in the specified time (default = 10s)
|
||||
|
||||
var common = require('../common.js');
|
||||
var util = require('util');
|
||||
|
||||
// if there are --dur=N and --len=N args, then
|
||||
// run the function with those settings.
|
||||
|
@ -26,42 +27,39 @@ function main(conf) {
|
|||
server();
|
||||
}
|
||||
|
||||
|
||||
function fail(syscall) {
|
||||
var e = new Error(syscall + ' ' + errno);
|
||||
e.errno = e.code = errno;
|
||||
e.syscall = syscall;
|
||||
throw e;
|
||||
function fail(err, syscall) {
|
||||
throw util._errnoException(err, syscall);
|
||||
}
|
||||
|
||||
function server() {
|
||||
var serverHandle = new TCP();
|
||||
var r = serverHandle.bind('127.0.0.1', PORT);
|
||||
if (r)
|
||||
fail('bind');
|
||||
var err = serverHandle.bind('127.0.0.1', PORT);
|
||||
if (err)
|
||||
fail(err, 'bind');
|
||||
|
||||
var r = serverHandle.listen(511);
|
||||
if (r)
|
||||
fail('listen');
|
||||
err = serverHandle.listen(511);
|
||||
if (err)
|
||||
fail(err, 'listen');
|
||||
|
||||
serverHandle.onconnection = function(clientHandle) {
|
||||
if (!clientHandle)
|
||||
fail('connect');
|
||||
serverHandle.onconnection = function(err, clientHandle) {
|
||||
if (err)
|
||||
fail(err, 'connect');
|
||||
|
||||
clientHandle.onread = function(buffer) {
|
||||
clientHandle.onread = function(nread, buffer) {
|
||||
// we're not expecting to ever get an EOF from the client.
|
||||
// just lots of data forever.
|
||||
if (!buffer)
|
||||
fail('read');
|
||||
if (nread < 0)
|
||||
fail(nread, 'read');
|
||||
|
||||
var writeReq = clientHandle.writeBuffer(buffer);
|
||||
var writeReq = {};
|
||||
err = clientHandle.writeBuffer(writeReq, buffer);
|
||||
|
||||
if (!writeReq)
|
||||
fail('write');
|
||||
if (err)
|
||||
fail(err, 'write');
|
||||
|
||||
writeReq.oncomplete = function(status, handle, req) {
|
||||
if (status)
|
||||
fail('write');
|
||||
fail(err, 'write');
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -90,22 +88,26 @@ function client() {
|
|||
}
|
||||
|
||||
var clientHandle = new TCP();
|
||||
var connectReq = clientHandle.connect('127.0.0.1', PORT);
|
||||
var connectReq = {};
|
||||
var err = clientHandle.connect(connectReq, '127.0.0.1', PORT);
|
||||
var bytes = 0;
|
||||
|
||||
if (!connectReq)
|
||||
fail('connect');
|
||||
if (err)
|
||||
fail(err, 'connect');
|
||||
|
||||
clientHandle.readStart();
|
||||
|
||||
clientHandle.onread = function(buffer) {
|
||||
if (!buffer)
|
||||
fail('read');
|
||||
clientHandle.onread = function(nread, buffer) {
|
||||
if (nread < 0)
|
||||
fail(nread, 'read');
|
||||
|
||||
bytes += buffer.length;
|
||||
};
|
||||
|
||||
connectReq.oncomplete = function() {
|
||||
connectReq.oncomplete = function(err) {
|
||||
if (err)
|
||||
fail(err, 'connect');
|
||||
|
||||
bench.start();
|
||||
|
||||
setTimeout(function() {
|
||||
|
@ -119,28 +121,27 @@ function client() {
|
|||
};
|
||||
|
||||
function write() {
|
||||
var writeReq
|
||||
var writeReq = { oncomplete: afterWrite };
|
||||
var err;
|
||||
switch (type) {
|
||||
case 'buf':
|
||||
writeReq = clientHandle.writeBuffer(chunk);
|
||||
err = clientHandle.writeBuffer(writeReq, chunk);
|
||||
break;
|
||||
case 'utf':
|
||||
writeReq = clientHandle.writeUtf8String(chunk);
|
||||
err = clientHandle.writeUtf8String(writeReq, chunk);
|
||||
break;
|
||||
case 'asc':
|
||||
writeReq = clientHandle.writeAsciiString(chunk);
|
||||
err = clientHandle.writeAsciiString(writeReq, chunk);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!writeReq)
|
||||
fail('write');
|
||||
|
||||
writeReq.oncomplete = afterWrite;
|
||||
if (err)
|
||||
fail(err, 'write');
|
||||
}
|
||||
|
||||
function afterWrite(status, handle, req) {
|
||||
if (status)
|
||||
fail('write');
|
||||
function afterWrite(err, handle, req) {
|
||||
if (err)
|
||||
fail(err, 'write');
|
||||
|
||||
while (clientHandle.writeQueueSize === 0)
|
||||
write();
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// as many bytes as we can in the specified time (default = 10s)
|
||||
|
||||
var common = require('../common.js');
|
||||
var util = require('util');
|
||||
|
||||
// if there are dur=N and len=N args, then
|
||||
// run the function with those settings.
|
||||
|
@ -26,27 +27,23 @@ function main(conf) {
|
|||
server();
|
||||
}
|
||||
|
||||
|
||||
function fail(syscall) {
|
||||
var e = new Error(syscall + ' ' + errno);
|
||||
e.errno = e.code = errno;
|
||||
e.syscall = syscall;
|
||||
throw e;
|
||||
function fail(err, syscall) {
|
||||
throw util._errnoException(err, syscall);
|
||||
}
|
||||
|
||||
function server() {
|
||||
var serverHandle = new TCP();
|
||||
var r = serverHandle.bind('127.0.0.1', PORT);
|
||||
if (r)
|
||||
fail('bind');
|
||||
var err = serverHandle.bind('127.0.0.1', PORT);
|
||||
if (err)
|
||||
fail(err, 'bind');
|
||||
|
||||
var r = serverHandle.listen(511);
|
||||
if (r)
|
||||
fail('listen');
|
||||
err = serverHandle.listen(511);
|
||||
if (err)
|
||||
fail(err, 'listen');
|
||||
|
||||
serverHandle.onconnection = function(clientHandle) {
|
||||
if (!clientHandle)
|
||||
fail('connect');
|
||||
serverHandle.onconnection = function(err, clientHandle) {
|
||||
if (err)
|
||||
fail(err, 'connect');
|
||||
|
||||
var chunk;
|
||||
switch (type) {
|
||||
|
@ -71,28 +68,27 @@ function server() {
|
|||
write();
|
||||
|
||||
function write() {
|
||||
var writeReq
|
||||
var writeReq = { oncomplete: afterWrite };
|
||||
var err;
|
||||
switch (type) {
|
||||
case 'buf':
|
||||
writeReq = clientHandle.writeBuffer(chunk);
|
||||
err = clientHandle.writeBuffer(writeReq, chunk);
|
||||
break;
|
||||
case 'utf':
|
||||
writeReq = clientHandle.writeUtf8String(chunk);
|
||||
err = clientHandle.writeUtf8String(writeReq, chunk);
|
||||
break;
|
||||
case 'asc':
|
||||
writeReq = clientHandle.writeAsciiString(chunk);
|
||||
err = clientHandle.writeAsciiString(writeReq, chunk);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!writeReq)
|
||||
fail('write');
|
||||
|
||||
writeReq.oncomplete = afterWrite;
|
||||
if (err)
|
||||
fail(err, 'write');
|
||||
}
|
||||
|
||||
function afterWrite(status, handle, req) {
|
||||
if (status)
|
||||
fail('write');
|
||||
function afterWrite(err, handle, req) {
|
||||
if (err)
|
||||
fail(err, 'write');
|
||||
|
||||
while (clientHandle.writeQueueSize === 0)
|
||||
write();
|
||||
|
@ -104,18 +100,19 @@ function server() {
|
|||
|
||||
function client() {
|
||||
var clientHandle = new TCP();
|
||||
var connectReq = clientHandle.connect('127.0.0.1', PORT);
|
||||
var connectReq = {};
|
||||
var err = clientHandle.connect(connectReq, '127.0.0.1', PORT);
|
||||
|
||||
if (!connectReq)
|
||||
fail('connect');
|
||||
if (err)
|
||||
fail(err, 'connect');
|
||||
|
||||
connectReq.oncomplete = function() {
|
||||
var bytes = 0;
|
||||
clientHandle.onread = function(buffer) {
|
||||
clientHandle.onread = function(nread, buffer) {
|
||||
// we're not expecting to ever get an EOF from the client.
|
||||
// just lots of data forever.
|
||||
if (!buffer)
|
||||
fail('read');
|
||||
if (nread < 0)
|
||||
fail(nread, 'read');
|
||||
|
||||
// don't slice the buffer. the point of this is to isolate, not
|
||||
// simulate real traffic.
|
||||
|
|
Загрузка…
Ссылка в новой задаче