Troubleshooting Connection Overload
Scenarios
Connection overload mainly occurs in two scenarios:
- Scenario 1: Connection counts continuously and slowly rise until reaching the maximum limit.
- Scenario 2: Connection counts surge suddenly, exhausting the connection pool.
Possible Causes
Scenario 1: Connection counts continuously and slowly rise until reaching the maximum limit.
- Improper configuration of the application connection pool causes connection leakage.
- View connection metrics on the Huawei Cloud console.
Log in to the Huawei Cloud console and click the instance name to go to the instance details page. In the navigation pane, choose DBA Assistant > Performance and view the metrics Current Active Connections and Total Connections. You can switch between real-time data and historical trend charts.
- Query connection status using SQL statements.
```plaintext show status like 'Threads_connected'; show variables like 'max_connections'; ```
- Check connection sources using real-time sessions provided by the Huawei Cloud console.
Log in to the Huawei Cloud console and click the instance name to go to the Summary page. In the navigation pane, choose DBA Assistant > Sessions. Check all session details, including client IP addresses, and filter or analyze session counts by IP address.
Check client connection pool configurations to ensure that connections can be properly released and reused.
- View connection metrics on the Huawei Cloud console.
- Idle connections are not released in a timely manner, causing connection accumulation.
- Check for idle connections using real-time sessions provided by the Huawei Cloud console.
Log in to the Huawei Cloud console and click the instance name to go to the Summary page. In the navigation pane, choose DBA Assistant > Sessions. In the session list, filter idle connections by selecting Sleep for the Command column and check their duration in the Time column.
- Query idle connections using SQL statements.
```plaintext select * from information_schema.processlist where command = 'Sleep' and time > 60; ```
- Configure idle timeout parameters.
Set wait_timeout and interactive_timeout using parameter templates. The default value is 28800 seconds (8 hours). Adjust these values based on business needs (such as 600 to 1800 seconds). Additionally, configure idle connection recycling parameters for client connection pools, such as minEvictableIdleTimeMillis and maxEvictableIdleTimeMillis for Druid connection pools. For more operations, see Modifying Parameters of an RDS for MySQL Instance.
- Check for idle connections using real-time sessions provided by the Huawei Cloud console.
- Connections are occupied because long-running transactions are not committed.
- Check for long-running transactions using real-time sessions provided by the Huawei Cloud console.
Log in to the Huawei Cloud console and click the instance name to go to the Summary page. In the navigation pane, choose DBA Assistant > Sessions to identify sessions with long execution times and check SQL text to determine whether they are long-running transactions.
- Query long-running transactions using SQL statements.
```plaintext select * from information_schema.innodb_trx order by trx_started; ```
Reduce long-running transactions by optimizing transaction logic, setting transaction timeouts, and avoiding time-consuming operations within transactions.
- Check for long-running transactions using real-time sessions provided by the Huawei Cloud console.
Scenario 2: Connection counts surge suddenly, exhausting the connection pool.
- Connection storms from applications generate massive connection requests in a short time.
Common connection storm scenarios:
- Type 1: A large number of connections are initialized when an application is started.
- Type 2: A sudden traffic surge causes the connection pool to expand rapidly.
- Type 3: The value of maxTotal configured for the connection pool is too large, exceeding the maximum connection limit of the instance.
- Type 4: The number of connections increases sharply due to abnormal retries of applications.
Huawei Cloud RDS for MySQL allows you to configure alarm rules for connection usage. You will receive notifications when the connection usage reaches the threshold. For details, see Configuring Alarm Rules.
- Slow database response causes connections to queue up.
Connection processing slows down and accumulates if the database encounters the following issues:
- Slow SQL statements block connections: Locate issues by using slow SQL analysis of DBA Assistant. For details, see Viewing Slow Query Logs.
- Lock waits cause connections to hang: Locate issues by using lock wait analysis of DBA Assistant. For details, see Managing Locks & Transactions.
- I/O bottlenecks cause response delays: View I/O metrics through real-time monitoring. For details, see Viewing Metrics.
Impact on Workloads
Connection overload prevents new connections from being established, causing "Too many connections" errors. Severe overload can make the service completely unavailable.
Handling Suggestions
- Preventive measures before overload occurs
- Configure application connection pool parameters properly. The pool's maximum connections should not exceed 70% to 80% of the instance's maximum connections. Configure appropriate connection timeouts and idle connection recycling times.
- Configure connection alarm thresholds on the Huawei Cloud console. Set the threshold to 70% to 80% of the instance's maximum connections. You will receive alarm notifications when the number of connections exceeds the threshold.
- Periodically check for connection leaks in your applications and ensure that connections are properly closed after use.
- Use parameter templates of Huawei Cloud RDS for MySQL to centrally manage database parameters. Set appropriate values for wait_timeout (recommended: 600 to 1800 seconds).
- Ensure that the idle timeout configured for the client connection pool is less than the value of the database parameter wait_timeout. This prevents invalid connections from being generated after the database disconnects connections in the connection pool.
- Emergency mitigation measures during overload
- Check for and terminate problematic sessions using real-time sessions.
Log in to the Huawei Cloud console and click the instance name to go to the Summary page. In the navigation pane, choose DBA Assistant > Sessions. In the session list, select idle connections or problematic sessions and click Kill Session to terminate them. Multiple sessions can be terminated in batches.
- Use SQL throttling to limit the concurrent execution of problematic SQL statements.
Log in to the Huawei Cloud console and click the instance name to go to the instance details page. In the navigation pane, choose DBA Assistant > SQL Analysis and Tuning and click the SQL Throttling tab. Create throttling rules to limit the concurrency of high-frequency problematic SQL queries, preventing further connection growth.
- Identify the root cause of the connection spike. Check whether the application has abnormal retry logic or connection pool misconfiguration.
- If more connections are needed, adjust the max_connections parameter on the console or upgrade instance specifications. During a specification upgrade, the instance remains accessible but connections are interrupted for seconds. Perform the upgrade during off-peak hours.
- Check for and terminate problematic sessions using real-time sessions.
FAQ
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot