MySQL Thread Pool plugin and application connection pools: coordinating two pooling layers for a low-traffic workload
0 reputation · 23 Jul 2021, 05:32 UTC
0 reputation · 23 Jul 2021, 05:32 UTC
Assume a low-traffic MySQL 8.x workload where the application tier already maintains its own connection pool, holding a small set of long-lived connections that sit idle most of the day. The deployment is licensed for Enterprise Edition, so the Thread Pool plugin is available as a second, server-side pooling layer; it is not included in Community Edition.
The unresolved decision is whether the two pooling layers should coexist. The client pool already bounds concurrent connections, so the plugin's core benefit — capping per-connection thread overhead under many active connections — may be marginal at this traffic level. Conversely, the plugin's group assignment and statement queueing could add scheduling latency that the client pool's timeout and keepalive assumptions do not anticipate, and it is unclear how thread_pool_size should relate to the client pool's maximum connection count.
thread_pool_size be chosen relative to the client pool's maximum connection count?29775 reputation · 23 Jul 2021, 06:12 UTC
In a low-traffic environment where the application tier already uses a connection pool, enabling the MySQL Thread Pool plugin is generally unnecessary and may introduce needless complexity. Its primary purpose is to prevent CPU exhaustion caused by thousands of concurrent active threads; if your client-side pool already limits active connections to a small number, the default 'one-thread-per-connection' model is more efficient.
For low-traffic workloads, the Thread Pool plugin does not produce measurable CPU or memory savings. In fact, it can introduce a slight overhead due to the logic required to manage thread groups and statement queues. Since the application-side pool already bounds the number of concurrent connections, the memory footprint of a few idle-side threads is negligible compared to the computational cost of the plugin's scheduling logic.
The Thread Pool plugin works by assigning connections to groups. If the number of active queries exceeds the thread_pool_size, new queries are queued. In a low-traffic scenario, this queue is rarely hit. However, if it does occur, the delay happens at the server level. Application-side pool timeouts might misinterpret this as a network lag or a slow query because the connection remains 'open' but the query is waiting for a worker thread. This can lead to 'ghost' timeouts where the client drops a connection while the server is just about to process the request.
If you choose to enable the plugin for future-proofing or consistency across environments, follow these sizing guidelines to coordinate the two layers:
Assumption: This analysis assumes 'low-traffic' refers to fewer concurrent active queries than the server's CPU core count, regardless of the total number of idle connections in the pool.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.