部署之后的应用在使用一段时间后,再打开就会变得十分慢;后来问support得知,是因为内存和连接数都消耗的差不多了:
As you can see from the above screenshot, it seems like you are using almost four more times memory than what you have. You are also using almost all the connections available (like 147 out of 150). I believe mysql has a hard limit so you can not scale connections like with other databases. You might have to implement connection pooling of some kind on the client side. If you want, we can try to restart the portals as that should clear the connections, and see if that helps for now。
MySQL对于连接数是有一定的上限的,不像其他的数据库,是可以自动增加的。
后来查了好久,才发现,
module.exports = {
mysql: {
host: 'host',
port: ‘port’,
user: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
database: process.env.DB,
connectionLimit: 50,
multipleStatements: true
}
};
NodeJS MySQL连接数这里设置的是50,本以为是要调大这个连接数才够用;
后来查找发现,每次启动server都会自动启动这50个连接;后台一共使用的是5个pods,那
show processlist;
总共会启动50*3=150个连接;
再加上测试的schema也是在这个库,所以再多加连接数,这样直接导致连接数不够;而且这个库的大部分连接都被test schema用了。
所以,这个也是坑,千万要考虑周全,不然就会导致应用特别慢。
网友评论