thread_cache_size

Tuning thread_cache_size variable
thread_cache_size limits the reusable connection threads retained after clients disconnect. It is not a limit on active connections and should not be sized by copying your usual concurrent-connection count.

Check the cache and thread-handling mode

These read-only checks apply to Oracle MySQL 8.4. The MariaDB distinction below is separate from the MySQL example.
SELECT VERSION() AS server_version,
       @@version_comment AS vendor_build,
       @@GLOBAL.thread_handling AS thread_handling,
       @@GLOBAL.thread_cache_size AS resolved_thread_cache_size;

SHOW GLOBAL STATUS
WHERE Variable_name IN (
  'Uptime', 'Connections', 'Aborted_connects',
  'Threads_created', 'Threads_cached', 'Threads_connected'
);
With the usual one-thread-per-connection model, a cached thread can serve a later connection. Oracle MySQL 8.4 documents an autosized default; SQL reports the resolved cache size, not an instruction to assign the default sentinel -1.

MariaDB handles defaults differently, including limiting the cache by max_connections. When MariaDB uses its thread pool, thread_cache_size is ignored. Do not transfer the MySQL default or a cache recommendation between vendors without checking the actual mode.

Read counters and gauges correctly

  • Connections counts connection attempts, including unsuccessful attempts.
  • Threads_created counts threads created to handle connections.
  • Aborted_connects records failed attempts to connect.
  • Threads_cached and Threads_connected are current counts, not interval totals.

Compare snapshots across a representative interval on the same instance, with no restart or counter reset. Your diagnostic connection also affects the observations. A snapshot with zero cached threads does not prove the cache is disabled or ineffective.

An increasing lifetime Threads_created total alone does not establish a problem. Check new connection attempts, failed connections, thread creation and application connection latency together. These counters do not provide a universal cache-size recommendation.

Separate connection reuse from connection capacity

Review application connection pooling and connection churn before proposing a server setting. Active concurrency belongs to the separate max_connections limit.

For ongoing observations, see MySQL monitoring. For a configuration review, explore MySQL configuration tuning with Releem.

Sources