angularjs - 在某个时间点监控事件的数据库连接

标签 angularjs node.js postgresql connection-pooling knex.js

引用我的问题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/

相关文章:

javascript - Angular 服务在回调函数中部分可用

javascript - 剑道 Angular 自动完成模板

javascript - 如何将 promise 的返回值分配给对象键?

mysql - MySQL 的 i18n(印度语)支持有什么问题吗?

ajax - ngtable服务器端分页

javascript - 用 promise 从失败中恢复过来

javascript - 如何在 require() 之后更改所需的连接

javascript - Node.Js 是否与应用程序的 iPhone Objective C 开发兼容?

sql - 选择列时选择整个表 - 如何

php - 从数据库中获取两列并呈现为单个数组