从aws lambda函数访问数据库时连接太多

aemubtdh  于 2021-07-07  发布在  Java
关注(0)|答案(0)|浏览(228)

我正在开发一个lambda,它将复制一些s3对象并对数据库进行一些更新。
输入来自sqs队列,最终将达到数百万。

Bean definition [io.micronaut.data.hibernate.operations.HibernateJpaOperations] could not be loaded: Error instantiating bean of type [javax.sql.DataSource]: Failed to initialize pool: Could not connect to address=(host=terraform-2020112813573819550000000d.cljpfhswxbks.us-east-1.rds.amazonaws.com)(port=3306)(type=master) : (conn=65) Too many connections: io.micronaut.context.exceptions.BeanInstantiationException
io.micronaut.context.exceptions.BeanInstantiationException: Bean definition [io.micronaut.data.hibernate.operations.HibernateJpaOperations] could not be loaded: Error instantiating bean of type [javax.sql.DataSource]: Failed to initialize pool: Could not connect to address=(host=terraform-2020112813573819550000000d.cljpfhswxbks.us-east-1.rds.amazonaws.com)(port=3306)(type=master) : (conn=65) Too many connections
...

我的数据源(application.yml)

datasources:
  default:
    url: ${JDBC_DATABASE_URL}
    username: ${DATABASE_USERNAME}
    password: ${DATABASE_PASSWORD}
    driverClassName: org.mariadb.jdbc.Driver
    schema-generate: CREATE_DROP
    maximum-pool-size: 50
    max-lifetime: 5000        # milliseconds
    connection-timeout: 5000  # milliseconds

当我测试队列中只有很少的项目(少于10个)时,我会得到“太多的连接”。如何让micronaut关闭连接、少打开或如何进行?
我正在使用jpa和hikari连接池。我很乐意发布我的代码,但我不认为这是相关的。
我正在使用terraform创建我的rds示例

resource "aws_db_instance" "rds" {
  name = "mydatabase"
  allocated_storage = 10
  engine = var.database_engine
  engine_version = var.database_engine_version
  instance_class = "db.t2.micro"
  username = "someUserName"
  password = random_password.password.result
  skip_final_snapshot = true
  apply_immediately = true

  vpc_security_group_ids = [aws_security_group.rds.id]
  db_subnet_group_name = aws_db_subnet_group.db.name

  parameter_group_name = aws_db_parameter_group.db.name
}

resource "aws_db_parameter_group" "db" {
  name = "rds-pg"
  family = "mariadb10.5"

  parameter {
    name = "max_connections"
    value = "80"
  }
}

我不确定“max\u connections”的默认值是多少,但80应该是1gb示例的最大值。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题