Disclaimer: I wrote a module to solve this problem.
npm install mysql-simple-pool
Now you can configure the connection pool. I use a maximum of 100 connections.
var Pool = require('mysql-simple-pool'); var pool = new Pool(100, { host: 'localhost', user: 'root', password: 'root', database: 'test' });
Now you can write a test function that will put this in the test.
function test() { var counter = 0; var start = new Date().getTime(); for (var xa = 0; xa < 10; xa++) { pool.query('SELECT SLEEP(1)', function(err, results) { counter++; if (counter == 10) { var end = new Date().getTime(); console.log('Time spend is ' + (end - start) + 'ms'); test(); } }); } } test();
And this is the result ...
Time spend is 1044ms Time spend is 1006ms Time spend is 1005ms Time spend is 1006ms Time spend is 1007ms Time spend is 1005ms Time spend is 1005ms Time spend is 1004ms Time spend is 1005ms Time spend is 1005ms
For the first time, some time is spent around him establishing connections. Hope this helps ~
Roel van uden
source share