Help Center/ GaussDB(for MySQL)/ Troubleshooting/ Connection Issues/ Error Message "connection established slowly"
Updated on 2024-09-05 GMT+08:00

Error Message "connection established slowly"

Scenario

During peak hours, the connection between a client and a GaussDB(for MySQL) instance often times out. As a result, it takes more than 10 seconds to log in to the instance.

Possible Causes

  1. View error logs of the DB instance to check whether the information "connection xxx is established slowly" is displayed. Example:

    If yes, some connections have timed out and have not been processed by the DB instance yet. When the connection between a client and the instance exceeds the specified timeout duration, an error is reported.

  2. Check the thread pool configuration (enabled by default) on the console.

    In the preceding figure, threadpool_size is set to 1, threadpool_stall_limit is set to 500 ms, and threadpool_oversubscribe is set to 3. The wait time for the thread pool to process connections is mainly related to the three parameters.

    • When all threads in the thread pool are busy, the scheduling thread in the thread pool creates a new thread every 500 ms (threadpool_stall_limit). Each thread group can process a new connection every 500 ms on average. If the queue is too long, the client may time out.
    • If all threads in the thread pool are busy, it means that the number of the threads has reached the upper limit. So when there are a large number of connections to be established, the number of total threads is calculated as follows: threadpool_size x (threadpool_oversubscribe + 1)

Solution

If there are a large number of new connections, increase the value of threadpool_oversubscribe to increase the total number of threads.

This reduces the overhead of repeated thread creation and destruction, and limits the number of running threads, thus protecting the system from crashing.

In normal cases, the thread pool is used when there are a large number of short connections. If persistent connections are used and there are a few connections (for example, the client uses a connection pool), the thread pool is not so helpful. In this case, adjust the values of threadpool_size and threadpool_oversubscribe to increase the total number of threads, or close the thread pool.