Performance: Connection pooling concept
Connection pooling affects how fast your app can open and reuse database connections, impacting response time and server load.
const pool = new Pool({ max: 10 });
const client = await pool.connect();
// query
client.release();const client = new Client(); await client.connect(); // query await client.end();
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No pooling (new connection per query) | N/A | N/A | N/A | [X] Bad |
| Using connection pool | N/A | N/A | N/A | [OK] Good |
const pool = mysql.createPool({ host: 'localhost', user: 'root', database: 'test' });
pool.query('SELECT 1 + 1 AS solution', (err, results) => {
if (err) throw err;
console.log(results[0].solution);
});const pool = mysql.createPool({ host: 'localhost', user: 'root' });
pool.getConnection((err, connection) => {
if (err) throw err;
connection.query('SELECT NOW()', (err, results) => {
if (err) throw err;
console.log(results);
connection.release();
});
});Pass the test and this pattern moves unknown