Last active
August 29, 2015 14:07
-
-
Save luckydrq/60a17bc4ffe8d35728ef to your computer and use it in GitHub Desktop.
node-mysql-pool-benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var benchmarks = require('beautify-benchmark'); | |
var Benchmark = require('benchmark'); | |
var mysql = require('mysql'); | |
var pool = mysql.createPool({ | |
host: 'x.x.x.x', | |
port: 8888, | |
user: 'test', | |
database: 'test_db', | |
password: '123456', | |
multipleStatements: true, | |
connectionLimit: 10 | |
}); | |
var suite = new Benchmark.Suite(); | |
suite | |
.add('pool#getConnection', function(deferred) { | |
pool.getConnection(function(err, connection) { | |
connection.query('SELECT * FROM comment', function(err, rows) { | |
connection.release(); | |
deferred.resolve(); | |
}); | |
}); | |
}, { defer: true }) | |
.add('pool#query', function(deferred) { | |
pool.query('SELECT * FROM comment', function(err, rows) { | |
deferred.resolve(); | |
}); | |
}, { defer: true }) | |
.on('cycle', function(event) { | |
benchmarks.add(event.target); | |
}) | |
.on('start', function(event) { | |
console.log('\n node version: %s, date: %s\n Starting...', process.version, Date()); | |
}) | |
.on('complete', function() { | |
benchmarks.log(); | |
process.exit(0); | |
}) | |
.run({ async: true }); | |
// Results: | |
// node version: v0.11.14, date: Thu Oct 23 2014 22:58:19 GMT+0800 (CST) | |
// Starting... | |
// 2 tests completed. | |
// pool#getConnection x 54.88 ops/sec ±2.22% (69 runs sampled) | |
// pool#query x 57.22 ops/sec ±2.51% (70 runs sampled) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment