Skip to content

Commit

Permalink
[misc] appveyor testing : removing node 6
Browse files Browse the repository at this point in the history
adding pool benchmark
  • Loading branch information
rusher committed Jul 12, 2018
1 parent 96c64ed commit 1f40093
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 28 deletions.
4 changes: 0 additions & 4 deletions appveyor.yml
Expand Up @@ -10,10 +10,6 @@ environment:
MUST_USE_TCPIP: 1
TEST_HOST: mariadb.example.com
matrix:
- DB: '10.2.14'
nodejs_version: "6"
MEM: "21"
SKIP_LEAK: "1"

- DB: '10.2.14'
MEM: "21"
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/benchmarkOne.js
Expand Up @@ -7,10 +7,10 @@ let bench;
const launchBenchs = function(path) {
bench = new Bench();

const test = "bench_select_param.js";
const test = "bench_promise_select_param_pool.js";
const m = require(path + "/" + test);
bench.initFcts.push(m.initFct);
bench.add(m.title, m.displaySql, m.benchFct, m.onComplete, m.promise); //, bench.CONN.MYSQL);
bench.add(m.title, m.displaySql, m.benchFct, m.onComplete, m.promise, m.pool); //, bench.CONN.MYSQL);

bench.suiteReady();
};
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/benchmarks.js
Expand Up @@ -18,7 +18,7 @@ const launchBenchs = function(path) {
console.log("benchmark: ./benchs/" + list[i]);
const m = require("./benchs/" + list[i]);
bench.initFcts.push(m.initFct);
bench.add(m.title, m.displaySql, m.benchFct, m.onComplete, m.promise);
bench.add(m.title, m.displaySql, m.benchFct, m.onComplete, m.promise, m.pool);
}

bench.suiteReady();
Expand Down
17 changes: 17 additions & 0 deletions benchmarks/benchs/bench_promise_select_param_pool.js
@@ -0,0 +1,17 @@
const assert = require("assert");

module.exports.title = "select number using promise and POOL";
module.exports.displaySql = "select 10000000";
module.exports.promise = true;
module.exports.pool = true;
module.exports.benchFct = function(pool, deferred) {
pool
.query("select ?", [1])
.then(rows => {
// assert.equal(rand, rows[0].t);
deferred.resolve();
})
.catch(err => {
throw err;
});
};
25 changes: 19 additions & 6 deletions benchmarks/common_benchmarks.js
Expand Up @@ -58,6 +58,8 @@ function Bench() {
const config = conf.baseConfig;
config.charsetNumber = 224;
config.trace = false;

const poolConfig = Object.assign({connectionLimit: 10},config);
// config.debug = true;
// if (!mariasql && process.platform === "win32") {
// config.socketPath = "\\\\.\\pipe\\MySQL";
Expand All @@ -76,6 +78,7 @@ function Bench() {
.createConnection(config)
.then(conn => {
connList["PROMISE_MYSQL"].drv = conn;
connList["PROMISE_MYSQL"].pool = promiseMysql.createPool(poolConfig);
dbReady("promise-mysql", this.driverLen);
})
.catch(err => {
Expand Down Expand Up @@ -113,6 +116,7 @@ function Bench() {
.then(conn => {
connList["PROMISE_MYSQL2"].drv = conn;
conn.on("error", err => console.log("driver mysql2 promise error :" + err));
connList["PROMISE_MYSQL2"].pool = promiseMysql2.createPool(poolConfig);
dbReady("promise mysql2", this.driverLen);
})
.catch(err => {
Expand All @@ -134,6 +138,7 @@ function Bench() {
.then(conn => {
connList["PROMISE_MARIADB"].drv = conn;
conn.on("error", err => console.log("driver mariadb promise error :" + err));
connList["PROMISE_MARIADB"].pool = mariadb.createPool(poolConfig);
dbReady("promise-mariadb", this.driverLen);
})
.catch(err => {
Expand Down Expand Up @@ -235,14 +240,22 @@ Bench.prototype.end = function(bench) {
bench.displayReport();
};

Bench.prototype.endConnection = function(conn) {
Bench.prototype.endConnection = async 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);
}
if (conn.pool) {
try {
await conn.pool.end();
} catch (err) {
console.log("ending error for pool '" + conn.desc + "'");
console.log(err);
}
}
};

Bench.prototype.displayReport = function() {
Expand Down Expand Up @@ -321,9 +334,9 @@ Bench.prototype.fill = function(val, length, right) {
return val;
};

Bench.prototype.add = function(title, displaySql, fct, onComplete, isPromise, conn) {
Bench.prototype.add = function(title, displaySql, fct, onComplete, isPromise, usePool, conn) {
const self = this;
const addTest = getAddTest(self, this.suite, fct, this.minSamples, title, displaySql, onComplete);
const addTest = getAddTest(self, this.suite, fct, this.minSamples, title, displaySql, onComplete, usePool);

if (conn) {
addTest(conn, conn.desc);
Expand Down Expand Up @@ -366,15 +379,15 @@ Bench.prototype.add = function(title, displaySql, fct, onComplete, isPromise, co
}
};

const getAddTest = function(self, suite, fct, minSamples, title, displaySql, onComplete) {
const getAddTest = function(self, suite, fct, minSamples, title, displaySql, onComplete, usePool) {
return function(conn, name) {
suite.add({
name: title + " - " + name,
fn: function(deferred) {
fct.call(self, conn.drv, deferred);
fct.call(self, usePool ? conn.pool : conn.drv, deferred);
},
onComplete: () => {
if (onComplete) onComplete.call(self, conn.drv);
if (onComplete) onComplete.call(self, usePool ? conn.pool : conn.drv);
},
minSamples: minSamples,
defer: true,
Expand Down
2 changes: 1 addition & 1 deletion promise.js
Expand Up @@ -16,7 +16,7 @@ module.exports.createConnection = function createConnection(opts) {
}
};

exports.createPool = function createPool(opts) {
module.exports.createPool = function createPool(opts) {
const options = new PoolOptions(opts);
const pool = new Pool(options);
pool.activatePool();
Expand Down
25 changes: 11 additions & 14 deletions test/integration/test-pool.js
Expand Up @@ -220,22 +220,19 @@ describe("Pool", () => {

pool.query("do 1");
pool.query("do 1").then(() => {
setImmediate(() => {
//waiting for rollback to end
assert.equal(pool.activeConnections(), 1);
assert.equal(pool.totalConnections(), 1);
assert.equal(pool.idleConnections(), 0);
assert.equal(pool.taskQueueSize(), 0);
setTimeout(() => {
//connection recreated
assert.equal(pool.activeConnections(), 0);
assert.equal(pool.totalConnections(), 1);
assert.equal(pool.idleConnections(), 1);
assert.equal(pool.totalConnections(), 2);
assert.equal(pool.idleConnections(), 2);
assert.equal(pool.taskQueueSize(), 0);
setTimeout(() => {
//connection recreated
assert.equal(pool.activeConnections(), 0);
assert.equal(pool.totalConnections(), 2);
assert.equal(pool.idleConnections(), 2);
assert.equal(pool.taskQueueSize(), 0);
pool.end();
done();
}, 250);
});
pool.end();
done();
}, 250);
});
});
});
Expand Down

0 comments on commit 1f40093

Please sign in to comment.