在某个时间点监视活动的数据库连接
在这里提到我的问题,我在使用Knex作为数据库库的NodeJS应用程序中遇到了Time-to-first-byte缓慢的问题。
版本:
- Postgres :9.6.1
- 节点 :7.4.0
- Knex :0.12.6
- angular度 :1.3
有人build议:
要解决这个问题,你需要看看你如何使用连接:
游泳池的大小
在所有请求中pipe理连接的方式
当我运行一个http请求时,如何查看活动连接以及knex如何pipe理池? 我怎样才能确保我的连接被最佳使用?
在Node中configurationknexconfiguration:
pool: { min: 2, max: 8, }
用DEBUG=knex:*
环境variables运行你的应用程序,你会看到非常详细的信息发生了什么事情。
应该给你足够的信息,看看时间在哪里。
如果你想像这样直接从generic-pool
请求统计信息:
knex = require('knex')({client: 'pg', connection: 'postgres:///knex_test'}) poolStats = { connectionsAvailable: knex.client.pool.availableObjectsCount(), connectionsUsed: knex.client.pool.inUseObjectsCount(), clientsWaitingForConnection: knex.client.pool.waitingClientsCount(), }; { connectionsAvailable: 2, connectionsUsed: 0, clientsWaitingForConnection: 0 }