引用我的问题here ,我在使用 Knex 作为数据库库的 NodeJS 应用程序中遇到了 Time-to-first-byte 的问题。
版本:
- Postgres:9.6.1
- Node :7.4.0
- Knex:0.12.6
- Angular :1.3
有人建议:
To solve this, you need to look into how you use the connections:
the size of the pool
the way connections are managed in all requests
当我运行 http 请求时,如何查看事件连接以及 knex 如何管理连接池?我如何才能确保我的连接得到最佳使用?
Node 中的池 knex 配置:
pool: {
min: 2,
max: 8,
}
最佳答案
使用 DEBUG=knex:*
环境变量运行您的应用程序,当您启动请求时,您将在 knex
中看到非常详细的信息和计时信息。
应该给你足够的信息来查看时间流逝的地方。
如果你想像这样直接从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 }
关于angularjs - 在某个时间点监控事件的数据库连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41927023/