具有 PostgreSQL 引擎连接限制的 RDS 数据库

RDS database with a PostgreSQL engine connection limit

我有一个 RDS 实例(db.t2.micro - 1 个 vCPU,1GiB RAM),我在短时间内通过连接尝试模拟数据库上的高负载并发送垃圾邮件无论数据库实例 class(我试过 db.t2.large - 4 vCPU,16GiB RAM),始终达到 ~100 的数据库连接限制,将 'max_connections' 参数设置为自定义参数组和使用 RDS proxy 连接池。

我确实注意到,当我增加数据库实例 class 时,下方数据库连接图中的红线消失了,这看起来应该有更多连接可用,但从图中可以看出,连接限制是固定在 ~100

我读过一些帖子,其中人们将数据库连接到 000 和 0000,所以我确信我在配置方面遗漏了一些东西,有什么想法吗?

编辑: 如果使用 JDBC 库,我可以超过 ~100 个连接,但是当我使用模拟我们的生产系统时,它是一个 REST API 运行 作为 AWS ECS 上的一项服务,我最大输出为 ~100,并出现 http 500 错误

CloudWatch 日志指示 'rate exceeded'。 REST API 是使用 Microsoft.NET.Sdk.Web 构建的。在我的用例中,服务器需要能够每 15 分钟每秒处理 ~500 API 个请求。

我真的对 Microsoft 和 .NET 知之甚少,但听起来您的应用程序有一个包含 100 个连接的默认连接池。

https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/sql-server-connection-pooling

在您的数据库连接字符串中尝试添加 Max Pool Size=200;

我怀疑你的 API,它已经确定是 REST api(可能是你正在使用的唯一一个,从信息中不确定)是“节流".

首先要确定它是否节流,请转到您的 CloudTrail console

然后为 CloudTrail trail 创建一个 table。

检查 Athena 控制台

然后 select 新查询,键入以下查询并将 table 名称替换为您创建的 clodtrail table。

select eventname, errorcode,eventsource,awsregion, useragent,COUNT(*) count 
FROM your-cloudtrail-table
where errorcode = 'ThrottlingException'
AND eventtime between '2020-10-11T03:00:08Z' and '2020-10-12T07:15:08Z'
group by errorcode,awsregion, eventsource, useragent, eventname
order by count desc;

一旦您确定您的 API 正在节流,如果节流是由于限制引起的,您可以要求 AWS 团队提高限制 (他们应该能够确认)。

有关限制相关对话,请参阅此内容: https://forums.aws.amazon.com/thread.jspa?threadID=226764

另请查看配额文档以了解 ECS 服务的限制: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-quotas.html

其次继续检查 PG 端显示的连接限制是什么,您可以 psql 进入它并 运行 命令: 显示 max_connections 或

postgres=> select * from pg_settings where name='max_connections';
-[ RECORD 1 ]---+-----------------------------------------------------
name            | max_connections
setting         | 83
unit            |
category        | Connections and Authentication / Connection Settings
short_desc      | Sets the maximum number of concurrent connections.
extra_desc      |
context         | postmaster
vartype         | integer
source          | configuration file
min_val         | 1
max_val         | 262143
enumvals        |
boot_val        | 100
reset_val       | 83
sourcefile      | /rdsdbdata/config/postgresql.conf
sourceline      | 33
pending_restart | f
Hope this helps!.

这将告诉您该特定实例的最大连接数限制。我知道没有这样的限制(理论上有限制)。 PG 中的连接限制是动态的,具体取决于 instance\cluster 的内存。 如果您转到 RDS,然后在左侧“参数组” 您可以搜索 max_connections 并检查列“值”

LEAST({DBInstanceClassMemory/9531392},5000).