Skip to content

Instantly share code, notes, and snippets.

@ifsnow
Last active July 24, 2017 09:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ifsnow/5cc2a628574c2708eb91231c1abe92cd to your computer and use it in GitHub Desktop.
Save ifsnow/5cc2a628574c2708eb91231c1abe92cd to your computer and use it in GitHub Desktop.
var mysql = require('mysql');
var MysqlPoolBooster = require('mysql-pool-booster');
var async = require('async'); // npm install async
var mode = process.argv[2] || 'booster';
if (mode === 'booster') {
mysql = MysqlPoolBooster(mysql);
}
var poolConfig = {
host : process.env.MYSQL_HOST,
user : process.env.MYSQL_USER,
password : process.env.MYSQL_PASSWORD,
connectionLimit : 50
};
var pool = mysql.createPool(poolConfig);
TOTAL_EXECUTIONS = 30000;
CONCURRENCY = 25;
// Creates dummy jobs
var jobs = [];
for (var i = 1; i <= TOTAL_EXECUTIONS; i++) {
jobs.push(i);
}
// Start benchmark
var startTime = process.hrtime();
async.eachLimit(jobs, CONCURRENCY, function (job, callback) {
pool.getConnection(function(err, connection) {
connection.query('SELECT 1', function(err) {
connection.release();
callback(err);
});
});
}, function() {
pool.end(function() {
var diff = process.hrtime(startTime);
var executionTime = diff[0] + diff[1] / 1e9;
console.log('- Execution time : ' + executionTime + ' seconds');
var executionsPerSecond = parseInt(TOTAL_EXECUTIONS / executionTime, 10);
console.log('- Executions per second : ' + executionsPerSecond);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment