Skip to content

Instantly share code, notes, and snippets.

@cjbj
Last active March 17, 2020 23:54
Show Gist options
  • Save cjbj/42062681d8445ee4495dbb096a2ef760 to your computer and use it in GitHub Desktop.
Save cjbj/42062681d8445ee4495dbb096a2ef760 to your computer and use it in GitHub Desktop.
'use strict';
process.env.UV_THREADPOOL_SIZE = 5;
const myPoolSize = 5; // poolMin & poolMax;
const numStmts = 5; // number of statements to run in parallel
console.log('UV_THREADPOOL_SIZE :', process.env.UV_THREADPOOL_SIZE );
console.log('poolMin & poolMax :', myPoolSize);
console.log('number of selects to run :', numStmts);
process.env.ORA_SDTZ = 'UTC';
const oracledb = require('oracledb');
const config = require('./dbconfig.js');
let executeCount = 0;
async function executeQuery(query) {
const c = executeCount++;
const startTime = Date.now();
console.log(`execute #${c}. Started at`, startTime);
let connection;
try {
connection = await oracledb.getConnection();
const result = await connection.execute(query);
//console.log(result.rows[0]);
const endTime = Date.now();
console.log(`execute #${c} took ${endTime - startTime} ms. Ended at`, endTime);
return result;
} catch (err) {
console.log(err);
} finally {
if (connection) {
await connection.close();
}
}
}
async function run() {
await oracledb.createPool({
user: config.user,
password: config.password,
connectString: config.connectString,
poolMax: myPoolSize,
poolMin: myPoolSize,
poolIncrement: 0
});
console.log('Pool creation complete');
let queries = new Array(numStmts);
queries.fill('select current_timestamp from dual');
queries.map(executeQuery);
await Promise.all(queries);
}
async function closePoolAndExit() {
console.log("\nTerminating");
try {
// Get the pool from the pool cache and close it
// If this hangs, you may need DISABLE_OOB=ON in a sqlnet.ora file
await oracledb.getPool().close(0);
console.log("Pool closed");
process.exit(0);
} catch(err) {
console.error(err.message);
process.exit(1);
}
}
process
.once('SIGTERM', closePoolAndExit)
.once('SIGINT', closePoolAndExit);
run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment