如何在RDS上通过MySQL正确使用Knex / Bookhelf

Mah*_*ooq 5 mysql amazon-rds node.js bookshelf.js knex.js

我有一个Node.js使用应用MySQLAWS RDS具有BookshelfKnex库。RDS实例具有一个max_connections90。我正在使用以下作为连接对象。

knex: {
  client: 'mysql',
    connection: {
      host: 'xxxxxxx.rds.amazonaws.com',
      user: 'xxx',
      password: 'xxxxx',
      database: 'xxxx',
      charset: 'utf8'
  },
  debug: true,
  pool: {
    min: 2,
    max: 20
  },
  acquireConnectionTimeout: 10000
},
Run Code Online (Sandbox Code Playgroud)
const config = require('./environment');
const knex = require('knex')(config.knex);
module.exports = require('bookshelf')(knex).plugin('registry');
Run Code Online (Sandbox Code Playgroud)
'use strict';

const bookshelf = require('../config/bookshelf');
const config = require('../config/environment');
module.exports = bookshelf.model(`TableA`, {
    tableName: 'TableA'
}, {});
Run Code Online (Sandbox Code Playgroud)

我对应用程序有很多要求,有时会因以下错误而崩溃。

未处理的拒绝TimeoutError:Knex:超时获取连接。游泳池可能已满。您是否缺少.transacting(trx)通话?

错误:ER_CON_COUNT_ERROR:连接过多

还我看到在服务器的连接数(上平均40至50)PROCESSLISTCommand作为sleep

我怀疑当90服务器上的所有连接完全使用完/ knex尝试从其池中获取新连接时,会发生这些错误。什么可能是对此的永久解决方案,以及处理此类应用程序的最佳实践。

Ric*_*mes 0

当客户端使用完 MySQL 后,将其断开连接。

另外,检查 的值wait_timeout。降低它会强制断开连接,而不是“睡眠”直到您回来。