RDS database with a PostgreSQL engine connection limit

Viewed 1597

I've got an RDS instance (db.t2.micro - 1 vCPU, 1GiB RAM) that I'm spamming with connection attempts to mimic high load on the DB over a short period of time and am consistently hitting a DB connection limit of ~100 regardless of the DB instance class (I've tried db.t2.large - 4 vCPU, 16GiB RAM), setting the 'max_connections' parameters as part of a custom parameter group and the use of an RDS proxy for connection pooling.

I do notice that the red line on the DB connections graph below disappears when I increase the DB instance class which looks like more connections should be available but as can be seen in the graph the connection limit is pretty fixed at ~100

I've read threads where people have DB connections into the 000s and 0000s even so I'm convinced I'm missing something here on the configuration side of things, any ideas?

RDS DB connections

Edit: I am able to exceed ~100 connections if using the JDBC library but when I use mimic our production system which is a REST API running as a service on AWS ECS, I max out at ~100, with a http 500 error RDS db conns http 500

The CloudWatch log indicates the 'rate exceeded'. The REST API is built using Microsoft.NET.Sdk.Web. In my use case the server needs to be able to handle ~500 API requests a second every 15mins. enter image description here

2 Answers

I'm suspecting that your API, which have already identified is the REST api(could be the only one you are using, not sure from the info) is "Throttling".

Firstly to identify if its throttling or not, go to your CloudTrail console

and then create a table for a CloudTrail trail.

check the Athena console

and then select New query, type the below query and replace the table name with your clodtrail table you created.

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;

Once you have identified for sure that your API is throttling, You can ask the AWS team to bump up the limit if the throttling is due to the limit (which they should be able to confirm).

see this for limit related conversation: https://forums.aws.amazon.com/thread.jspa?threadID=226764

also check out the quota doc for the limits on ECS service: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-quotas.html

Secondly go ahead and check the PG end what is the connections limit showing there, you can psql into it and run the command: show max_connections or

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!.

This will tell you the max connections limit for that particular instance. I know there is no limit as such(there is a theoretical limit). The connection limit is dynamic in PG depending on the memory of your instance\cluster. IF you go to RDS and then on the left side "Parameter groups" you can search for max_connections and check for the column "values"

LEAST({DBInstanceClassMemory/9531392},5000).
Related