Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

731
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda