Reputation: 2896
I am working on tuning the AWS RDS (Postgres) performance.
With the current setting (default),
db.t2.micro
max_connections: {DBInstanceClassMemory/31457280} // => about 34 connections
I ran performance test using Gatling, with 100 concurrent requests (one request one connection). Report showed that 78 successful requests, 22 failed requests.
I have few questions:
1/ How can RDS support up to 78 connections while the max_connections is 34?
2/ Is there any dynamic way to adjust the max_connections when the number of request exceeds the max_connections?
Note: I know how to change the value of max_connections by hardcode.
Upvotes: 1
Views: 8571
Reputation: 2863
1) At any point in time, if the number of concurrent connections >max_connections, RDS will respond with "too many connections"
error for new requests, until it is able to release already existing connections. The server rejects any excessive connection attempts. So when you run performance testing with Gatling, do check in the database(by logging into Postgres sql and checking with a query), how many connections are getting established to process the requests.
2) As far as dynamically changing the max_connections parameter is concerned, max_connection
is a static parameter in Postgres, meaning you require a DB instance restart before that parameter takes effect. In MySQL though, it is a dynamic parameter. I recommend you not to consider this approach of dynamically modifying this parameter value in production environments. But if you really want to dynamically change it for testing purpose, you can try the below (untested) method:
Create a cloudwatch alarm MaxDbConnection
with condition
dbconnections > 25(considering t2.micro as an example).
Create a SNS topic exclusively for the above alarm and add it under
the Actions section of MaxDbConnection
alarm.
Create a lambda function and select the SNS topic created above as its trigger.
In the lambda function, you can write a logic to modify the max_connection parameter using the modify-db-parameter-group
method using any sdk of your
choice. Also, verify the changes are applied using
DescribeDBParameters
method.
Upvotes: 0