Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

723
Views
Knex.js - how to use max number of connections in pool

I am using Knex.js with MySQL and would like to utilize a connection pool, as the test is under heavy load.

Even though I have set the pool.max to 10, I never see more than 1 connection being used. Here is an example that runs a query every 100ms:

    const db = require("knex")({
      client: "mysql",
      connection: {
        user: "admin",
        password: "xx!",
        database: "xx",
        host: "xx",
        port: 3306,
      },
      debug: false,
      pool: {
        min: 2,
        max: 10,
      },
    });
    
    (async () => {
      setInterval(async () => {
        await db("titles").select(1).limit(1);
    
        console.log("numUsed", db.client.pool.numUsed());
        console.log("numFree", db.client.pool.numFree());
    
        console.log("--");
          }, 100);
        
        })();

When I run this I see the following:

numUsed 2
numFree 0
--
numUsed 2
numFree 0
--
numUsed 3
numFree 0
--
numUsed 2
numFree 1
--
numUsed 1
numFree 2
--
numUsed 1
numFree 3
--
numUsed 0
numFree 5
--
numUsed 1
numFree 4
--
numUsed 0
numFree 5
--
numUsed 0
numFree 5
--
numUsed 0
numFree 5
--
numUsed 0
numFree 5

We can see here the number used DOES increase to a max of 3 then reduces to 0. I dont understand this behavior and cannot find anything documented to explain.

Is there anything I should be doing to manually to force use of a pool resource?

I see in the tarn.js docs (pool used my knex) there are methods to acquire() and release(). My expectation (given it is not documented) is that Knex manages this for me.

Appreciate any guidance.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!