I have connected an AWS Lambda function to Amazon RDS (MySQL). When the Lambda function is invoked 100 times simultaneously, there are almost 400 connections opened in RDS (as shown in RDS console). Why is this?
我已将AWS Lambda函数连接到Amazon RDS(MySQL)。同时调用Lambda函数100次时,在RDS中打开了近400个连接(如RDS控制台中所示)。为什么是这样?
I checked the active connections using:
我使用以下方法检查了活动连接
SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST WHERE DB = "MYDB";
All the connections are from Lambda containers. Does anyone know how Lambda containers act on simultaneous requests? Why are the containers not reused?
所有连接都来自Lambda容器。有谁知道Lambda容器如何对同时请求起作用?为什么容器不能重复使用?
Current Configuration:
var sequelize = new Sequelize('DB','username', 'password' ,{ dialect: 'mysql', port: port, host: host, pool: { max: 20, min: 0, idle: 300000 } });
var sequelize = new Sequelize('DB','username','password',{dialect:'mysql',port:port,host:host,pool:{max:20,min:0,idle:300000}}) ;
Even if one connection is opened per request it should be 100. How 400 connections are opened?
即使每个请求打开一个连接,它也应该是100.如何打开400个连接?
I'm using Sequelize. Node JS 6.9.1
我正在使用Sequelize。节点JS 6.9.1
Note: Connection Happens only once outside Lambda Handler method
注意:连接仅在Lambda Handler方法之外发生一次
1 个解决方案
#1
0
Sequelize by defaults creates a connection pool, so it's creating 4 connections because it's designed to run as a long running service. You can disable this by setting options.pool
to false
see the API reference
默认情况下,Sequelize会创建一个连接池,因此它创建了4个连接,因为它设计为作为长时间运行的服务运行。您可以通过将options.pool设置为false来禁用此功能,请参阅API参考
However as your application scales this is a fundamental problem with Lambda that won't go away. I recommend building a DB proxy layer in EC2 to terminate your db connections (i.e. using ProxySQL). It will then have a connection pool to the rds db.
但是,随着您的应用程序扩展,这是Lambda的基本问题,不会消失。我建议在EC2中构建一个DB代理层来终止数据库连接(即使用ProxySQL)。然后它将有一个到rds db的连接池。
The only way around this is to use dynamodb as your backend store.
解决这个问题的唯一方法是使用dynamodb作为后端存储。
#1
0
Sequelize by defaults creates a connection pool, so it's creating 4 connections because it's designed to run as a long running service. You can disable this by setting options.pool
to false
see the API reference
默认情况下,Sequelize会创建一个连接池,因此它创建了4个连接,因为它设计为作为长时间运行的服务运行。您可以通过将options.pool设置为false来禁用此功能,请参阅API参考
However as your application scales this is a fundamental problem with Lambda that won't go away. I recommend building a DB proxy layer in EC2 to terminate your db connections (i.e. using ProxySQL). It will then have a connection pool to the rds db.
但是,随着您的应用程序扩展,这是Lambda的基本问题,不会消失。我建议在EC2中构建一个DB代理层来终止数据库连接(即使用ProxySQL)。然后它将有一个到rds db的连接池。
The only way around this is to use dynamodb as your backend store.
解决这个问题的唯一方法是使用dynamodb作为后端存储。