Hello everyone,
Does anyone know how AWS came up with this magic number for estimating DBConnections for AWS RDS.
I understand from stack exchange posts that this is not accurate but close.
I am hoping to get more detailed understanding if anyone was already aware of the reason behind this?
The formula was
max_connections = DBInstanceClassMemory/12582880
which is 12.58 MB approximately
My guess is that they measured how much memory each marginal connection used. No idea though
Yes, something like that. `12582880` is around 12MB used to handle a single connection.
It’s quite close to 12 MiB (12 * 1024 * 1024 = 12582912) with exactly 32 bytes missing.
It’s also different for different db engines, this value is for MySQL. It’s detailed here (not explained how they come with the numbers, but I agree probably measured/derived with vendors) https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Limits.html
I’m still bitter about MB vs MiB. It’d be like if I decided a liter was now 900ml and if you want 1000ml liters it’s called a liiter.
This formula is based on the amount of memory allocated to the particular database instance class.
The reasoning behind this formula is as follows:
-
Memory Allocation for Connections: Each database connection requires a certain amount of memory to handle the client session and associated resources. The exact memory requirement varies depending on the database engine, configuration settings, and workload characteristics.
-
Default Connection Memory Usage: AWS assumes a default memory usage of around 12MB per connection for most database workloads. This value (12582880 bytes) is derived from the assumption that each connection requires approximately 12MB of memory.
-
Balancing Connections and Memory: By dividing the total memory allocated to the database instance class by the assumed memory usage per connection (12582880 bytes or ~12MB), AWS calculates the maximum number of connections that can be reasonably supported by the instance’s memory capacity.
-
Preventing Excessive Memory Usage: Setting the max_connections parameter helps prevent the database from accepting more connections than it can handle with its available memory. This helps avoid out-of-memory situations and potential performance degradation or crashes due to excessive memory usage.