When the client initiates a query to the server, a connection is established with the server. MySQL provides the maximum number of connections. Therefore, each time a connection is established
When the client initiates a query to the server, a connection is established with the server. MySQL provides the maximum number of connections. Therefore, each time a connection is established
When the client initiates a query to the server, a connection is established with the server. MySQL provides the maximum number of connections. Therefore, each time a connection is established successfully, when the server assigns a processing thread to the connection, it will determine whether the current number of connections has operated the configured maximum number of connections. If it has exceeded, the thread will not be reallocated for processing, and the connection will be closed directly.
Static void create_new_thread (THD * thd)
{
DBUG_ENTER ("create_new_thread ");
/*
Don't allow too restart connections. We roughly check here that we allow
Only (max_connections + 1) connections.
*/
Mysql_mutex_lock (& LOCK_connection_count );
If (connection_count> = max_connections + 1 | abort_loop)
{// Determine whether the maximum connection exceeded or whether it indicates termination. The maximum connection is configured in the my. ini file,
Mysql_mutex_unlock (& LOCK_connection_count );
DBUG_PRINT ("error", ("Too many connections "));
Close_connection (thd, ER_CON_COUNT_ERROR );
Delete thd;
DBUG_VOID_RETURN;
}
+ + Connection_count; // If NO, increase the number of connections
If (connection_count> max_used_connections)
Max_used_connections = connection_count; // increase the maximum number of connections
Mysql_mutex_unlock (& LOCK_connection_count );
/* Start a new thread to handle connection .*/
Mysql_mutex_lock (& LOCK_thread_count );
/*
The initialization of thread_id is done in create_embedded_thd ()
The embedded library.
TODO: refactor this to avoid code duplication there
*/
Thd-> thread_id = thd-> variables. pseudo do_thread_id = thread_id ++;
Thread_count ++; // increase the number of threads and prepare to allocate threads for the connection)
MYSQL_CALLBACK (thread_schedconnection, add_connection, (thd ));
DBUG_VOID_RETURN;
}