correcting benchmark to permit using named pipe and warming driver to have more accurate results.

connection ending correction for named pipe + test
This commit is contained in:
rusher
2018-03-12 17:08:13 +01:00
parent bebf8dc2ca
commit cc56e3f461
5 changed files with 83 additions and 32 deletions

View File

@ -12,7 +12,7 @@ var launchBenchs = function(path) {
var test = 'bench_select_param.js';
var m = require(path + '/' + test);
bench.initFcts.push(m.initFct);
bench.add(m.title, m.displaySql, m.benchFct, m.onComplete);
bench.add(m.title, m.displaySql, m.benchFct, m.onComplete, bench.CONN.MARIADB);
};
fs.access('./benchs', function(err) {

View File

@ -13,15 +13,20 @@ try {
}
function Bench(callback) {
let dbReady = 0;
this.dbReady = 0;
this.reportData = {};
const ready = function(name) {
console.log('driver for ' + name + ' connected');
dbReady++;
if (dbReady === (mariasqlC ? 4 : 3)) {
console.log('run bench');
callback();
bench.dbReady++;
if (bench.dbReady === (mariasqlC ? 4 : 3)) {
bench.dbReady = 0;
bench.warmupConnection(bench.CONN.MYSQL, 0, bench, callback);
bench.warmupConnection(bench.CONN.MYSQL2, 0, bench, callback);
bench.warmupConnection(bench.CONN.MARIADB, 0, bench, callback);
if (mariasqlC) {
bench.warmupConnection(bench.CONN.MARIASQLC, 0, bench, callback);
}
}
};
@ -32,28 +37,21 @@ function Bench(callback) {
}
this.CONN = {};
var bench = this;
this.CONN['MYSQL'] = { drv: mysql.createConnection(config), desc: 'mysql' };
this.CONN.MYSQL.drv.connect(function() {
ready('mysql');
});
this.CONN.MYSQL.drv.connect(() => ready('mysql'));
this.CONN['MYSQL2'] = {
drv: mysql2.createConnection(config),
desc: 'mysql2'
};
this.CONN.MYSQL2.drv.connect(function() {
ready('mysql2');
});
this.CONN.MYSQL2.drv.connect(() => ready('mysql2'));
this.CONN['MARIADB'] = {
drv: mariadb.createConnection(config),
desc: 'mariadb'
};
this.CONN.MARIADB.drv.connect(function() {
ready('mariadb');
});
this.CONN.MARIADB.drv.connect(() => ready('mariadb'));
if (mariasqlC) {
const configC = Object.assign({}, config);
@ -63,16 +61,17 @@ function Bench(callback) {
drv: new mariasqlC(configC),
desc: 'mariasqlC'
};
this.CONN.MARIASQLC.drv.connect(function() {
ready('mariasqlC');
});
this.CONN.MARIASQLC.drv.connect(() => ready('mariasqlC'));
}
this.initFcts = [];
this.queue = true;
this.async = true;
//200 is a minimum to have benchmark average variation of 1%
this.minSamples = 200;
const bench = this;
this.suite = new Benchmark.Suite('foo', {
// called when the suite starts running
onStart: function() {
@ -113,17 +112,44 @@ function Bench(callback) {
});
}
Bench.prototype.warmupConnection = (conn, i, bench, cb) => {
conn.drv.query('SELECT ' + i++, () => {
if (i < 15000) {
bench.warmupConnection(conn, i, bench, cb);
} else {
bench.dbReady++;
console.log('warmup done for ' + conn.desc);
if (bench.dbReady === (mariasqlC ? 4 : 3)) {
console.log("initial warmup finished");
cb();
}
}
});
}
Bench.prototype.end = function(bench) {
this.CONN.MARIADB.drv.end();
this.CONN.MYSQL.drv.end();
this.CONN.MYSQL2.drv.end();
this.endConnection(this.CONN.MARIADB);
this.endConnection(this.CONN.MYSQL);
this.endConnection(this.CONN.MYSQL2);
if (mariasqlC) {
this.CONN.MARIASQLC.drv.end();
this.endConnection(this.CONN.MARIASQLC);
}
bench.displayReport();
};
Bench.prototype.endConnection = function(conn) {
try {
//using destroy, because MySQL driver fail when using end() for windows named pipe
conn.drv.destroy();
} catch (err) {
console.log("ending error for connection '" + conn.desc + "'");
console.log(err);
}
};
Bench.prototype.displayReport = function() {
const simpleFormat = new Intl.NumberFormat('en-EN', {
maximumFractionDigits: 1

View File

@ -44,14 +44,13 @@
"devDependencies": {
"benchmark": "^2.1.4",
"chai": "^4.1.2",
"colors": "^1.1.2",
"colors": "^1.2.1",
"error-stack-parser": "^2.0.1",
"eslint": "^4.18.1",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-async-await": "0.0.0",
"eslint-plugin-markdown": "^1.0.0-beta.7",
"microtime": "^2.1.7",
"mocha": "^5.0.1",
"mocha": "^5.0.4",
"mysql": "^2.15.0",
"mysql2": "^1.5.2",
"prettier": "^1.10.2",

View File

@ -178,6 +178,7 @@ class Connection {
end(callback) {
this._clearConnectTimeout();
this.addCommand = this._addCommandDisabled;
this._closing = true;
this._addCommandEnable(new Quit(this.events, callback));
}
@ -188,7 +189,7 @@ class Connection {
this._clearConnectTimeout();
this.addCommand = this._addCommandDisabled;
this._closing = true;
this._commands.clear();
this.cmdQueue.clear();
if (this.cmd) {
//socket is closed, but server may still be processing a huge select
@ -288,8 +289,7 @@ class Connection {
}
let packetInputStream = new PacketInputStream(this);
let conn = this;
socket.on("error", conn._fatalError.bind(conn));
socket.on("error", this._socketError.bind(this));
socket.on("data", chunk => packetInputStream.onData(chunk));
this.out.setWriter(buffer => this._socket.write(buffer));
@ -297,6 +297,12 @@ class Connection {
this._socket = socket;
}
_socketError(err) {
if (!this._closing) {
this._fatalError(err);
}
}
_dispatchPacket(packet, header) {
if (this.opts.debug && packet && this.cmd) {
console.log(
@ -352,7 +358,7 @@ class Connection {
let packetInputStream = new PacketInputStream(this);
let events = this.events;
secureSocket.on("error", this._fatalError.bind(this));
secureSocket.on("error", this._socketError.bind(this));
secureSocket.on("data", chunk => packetInputStream.onData(chunk));
secureSocket.on("secureConnect", () => {
events.emit("secureConnect");

View File

@ -0,0 +1,20 @@
"use strict";
const base = require("../base.js");
const ServerStatus = require("../../src/const/server-status");
const assert = require("chai").assert;
describe("test socket", () => {
it("named pipe", function(done) {
if (process.platform !== 'win32') this.skip();
const conn = base.createConnection({socketPath: '\\\\.\\pipe\\MySQL'});
conn.query("DO 1", (err, res) => {
if (err) done(err);
conn.end(() => {
done();
});
})
});
});