简体   繁体   中英

how to initialize knex.js connection/pool

It takes ~40 seconds to respond first time I call query/getData(). Second time it takes just a second.. So assume first time it initializes connection/pool.. How do I force it at service start?

var knex = require('knex')({
  client: 'oracledb',
  connection: {
    user: ORACLE_USER,
    password: ORACLE_PWD,
    connectString: ORACLE_CONNECT_STRING
  },
  pool: {
    min: 4,
    max: 4,
    acquireTimeoutMillis: 100000,
    idleTimeoutMillis: 100000
  }
});

......

class DbHelper {
    getData(){
         return knex.raw(`SELECT ....

Sounds like you have some problems connecting the database... there is no reason why first connections should take 40 seconds to complete.

Knex doesn't do any pool initialization, but when query is done and if there are no free connections in pool, it allocates a new one or in case if pool is full it waits until some other connection is returned to the pool.

Anyways if you really want to fill the pool on startup you can do for example pool max amount of concurrent queries and then pool should be filled with connections.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM