Permalink
Browse files

Stats improved; ENOBUFS workaround improved; bugs fixed

  • Loading branch information...
1 parent 29e1b15 commit 55be73a89ab6bbe496bbc611d661647cf521f897 @penartur committed May 5, 2012
Showing with 45 additions and 16 deletions.
  1. +45 −16 lib/benchmark.js
View
@@ -3,6 +3,7 @@
var request = require('request');
var WorkingQueue = require('capisce').WorkingQueue;
var http = require('http');
+var os = require('os');
var dateTimer = require('./timers/datetimer');
@@ -21,8 +22,8 @@ var getTimer = function (timerType) {
var statistics = {
temporalDisrepancy: function (list) {
- var sliceLength = Math.min(list.length / 2, 64);
- return Math.round(100 * this.trimmedMean(list.slice(list.length - sliceLength, list.length)) / this.trimmedMean(list.slice(0, sliceLength))) / 100;
+ var sliceLength = Math.min(list.length / 2, 8);
+ return Math.round(100 * this.trimmedMean(list.slice(-sliceLength)) / this.trimmedMean(list.slice(0, sliceLength))) / 100;
},
sort: function (list) {
if (!list.sorted) {
@@ -33,7 +34,7 @@ var statistics = {
median: function (list) {
this.sort(list);
if (list.length % 2 == 0) {
- return Math.round(list[list.length / 2 - 1] + list[list.length / 2]) / 2
+ return Math.round((list[list.length / 2 - 1] + list[list.length / 2]) / 2);
} else {
return list[(list.length - 1) / 2];
}
@@ -66,13 +67,17 @@ var statistics = {
this.sort(list);
var median = this.median(list);
var trimmedMean = this.trimmedMean(list);
+ var top10 = this.mean(list.slice(0, list.length / 10));
+ var bottom10 = this.mean(list.slice(-list.length / 10));
var result = {
trimmedMean: trimmedMean
, median: median
, temporalDisrepancy: temporalDisrepancy
, mean: mean
, max: max
, num: num
+ , top10: top10
+ , bottom10: bottom10
};
//console.log(result);
return result;
@@ -117,17 +122,22 @@ var BenchmarkContext = function (benchmark, simultaneousRequests, done) {
this.responseTimes[pageName][engineName] = [];
}
}
+
+ this.totals = {};
}
BenchmarkContext.prototype.onDone = function () {
- var stats = {};
+ var perPage = {};
for (var pageName in this.benchmark.pages) {
- stats[pageName] = {};
+ perPage[pageName] = {};
for (var engineName in this.benchmark.engines) {
- stats[pageName][engineName] = statistics.all(this.responseTimes[pageName][engineName]);
+ perPage[pageName][engineName] = statistics.all(this.responseTimes[pageName][engineName]);
}
}
- this.done(this.simultaneousRequests, stats);
+ this.done(this.simultaneousRequests, {
+ perPage: perPage,
+ totals: this.totals
+ });
}
BenchmarkContext.prototype.requestPage = function (url, expectedLength, callback) {
@@ -163,7 +173,7 @@ BenchmarkContext.prototype.runPage = function (engineName, pageName, over) {
BenchmarkContext.prototype.runEngine = function (engineName, over) {
var tasks = 0;
- console.log("runEngine");
+ //console.log("runEngine");
var queue = new WorkingQueue(this.simultaneousRequests);
queue.hold();
for (var i = 0; i < this.benchmark.options.iterations * this.simultaneousRequests; i++) {
@@ -174,11 +184,19 @@ BenchmarkContext.prototype.runEngine = function (engineName, over) {
}
}
}
- queue.whenDone(function () {
- var timeout = tasks * 10;
- console.log("done, waiting " + timeout + "ms");
- setTimeout(over, tasks * 10); //to workaround ENOBUFS
- });
+ var timer = this.benchmark.timers.start();
+ queue.whenDone((function () {
+ this.totals[engineName] = {
+ time: timer.elapsed(),
+ tasks: tasks
+ };
+ var timeout = 0;
+ if (os.platform() == 'win32') {
+ timeout = this.simultaneousRequests * 2000; //to workaround ENOBUFS
+ }
+ //console.log("done, waiting " + timeout + "ms");
+ setTimeout(over, timeout);
+ }).bind(this));
queue.go();
}
@@ -221,7 +239,10 @@ Benchmark.prototype.runMultiple = function (simultaneousRequestsList, callback,
Benchmark.prototype.showStats = function (simultaneousRequests, stats) {
var Table = require('cli-table');
console.log("Statistics for " + simultaneousRequests + " simultaneous requests");
- for (var pageName in stats) {
+ for (var engineName in stats.totals) {
+ console.log("Processing " + engineName + " took " + stats.totals[engineName].time + " (" + (stats.totals[engineName].time / stats.totals[engineName].tasks) + " per request)");
+ }
+ for (var pageName in stats.perPage) {
console.log(pageName);
var table = new Table({
head: [
@@ -230,6 +251,8 @@ Benchmark.prototype.showStats = function (simultaneousRequests, stats) {
'Median',
'Temporal disrepancy',
'Mean',
+ 'Top 10%',
+ 'Bottom 10%',
'Max',
'Sample size'
],
@@ -239,6 +262,8 @@ Benchmark.prototype.showStats = function (simultaneousRequests, stats) {
8,
21,
8,
+ 9,
+ 12,
8,
13
],
@@ -249,17 +274,21 @@ Benchmark.prototype.showStats = function (simultaneousRequests, stats) {
'right',
'right',
'right',
+ 'right',
+ 'right',
'right'
]
});
- for (var engineName in stats[pageName]) {
- var entry = stats[pageName][engineName];
+ for (var engineName in stats.perPage[pageName]) {
+ var entry = stats.perPage[pageName][engineName];
table.push([
engineName,
entry.trimmedMean,
entry.median,
entry.temporalDisrepancy,
entry.mean,
+ entry.top10,
+ entry.bottom10,
entry.max,
entry.num
]);

0 comments on commit 55be73a

Please sign in to comment.