node-mssql 如何处理连接池?

How does node-mssql handle connection pooling?

我正在使用 node-mssql 包在 Node 中创建一个 API 端点。

我想知道这个包是如何处理连接池的,因为 package website 上没有太多解释。

我的配置中有以下内容,以允许池增加到 10 个。

var config = {
  server: '',
  user: '',
  password: '',
  database: '',
  pool: {
    max: 10,
    min: 0,
    idleTimeoutMillis: 30000
  }
}

我已将这些行添加到每个请求中,因此我可以在 Node 控制台中查看发生了什么...

// Dump info about connection pool
console.log('SQL Pool - waitingClientsCount: ' + connection.pool.waitingClientsCount())
console.log('SQL Pool - getPoolSize: ' + connection.pool.getPoolSize())
console.log('SQL Pool - availableObjectsCount: ' + connection.pool.availableObjectsCount())

我已经在我的浏览器中导航到端点并保持刷新几分钟。在 Node 控制台中,上面的每个输出都是这样的...

SQL Pool - waitingClientsCount: 0
SQL Pool - getPoolSize: 1
SQL Pool - availableObjectsCount: 0

我原以为池大小会随着所有这些请求而增加。

池是根据负载自动配置的,还是我误解了什么?

编辑:从外观上看,该软件包正在使用 Tedious 驱动程序。

在 GitHub 上的项目问题跟踪器中找到了答案:https://github.com/patriksimek/node-mssql/issues/118#issuecomment-92522160

答案是...

Clarkey, IIRC the default pool size is 10, and if your requests return fast enough... the first connection will simply be reused... if you use something like siege if you really want to test things. Also, iirc the connection will stay open for something like 30 or 60 seconds before being cycled out.