De acordo com os documentos do MySQL, você deve definir thread_cache_size
para que a maioria das novas conexões use threads do cache em vez de threads recém-criados. Isso economiza parte da sobrecarga de criação de threads, embora normalmente não crie uma melhoria significativa no desempenho:
Requests for threads are satisfied by reusing threads taken from the
cache if possible, and only when the cache is empty is a new thread
created. This variable can be increased to improve performance if you
have a lot of new connections. Normally, this does not provide a
notable performance improvement if you have a good thread
implementation. However, if your server sees hundreds of connections
per second you should normally set thread_cache_size high enough so
that most new connections use cached threads. (source)
Isso significa que você deve definir seu thread_cache_size
para que Threads_created / Connections
(o% de conexões que levam à criação de novos segmentos) seja bastante baixo. Se você pegar os documentos do MySQL literalmente ("most"), o valor deve ser < 50%. A resposta de RolandoMySQLDBA diz < 1%. Eu não sei quem está mais perto da verdade.
Você deve não definir thread_cache_size
maior que Max_used_connections
. A frase final na resposta de RolandoMySQLDBA ("No mínimo, thread_cache_size deve ser maior que Max_used_connections") não parece sensata porque diz que você deve manter mais threads no cache do que seu servidor ever usa . O MySQL nunca colocará tantos encadeamentos no cache de qualquer maneira - ele não coloca os encadeamentos no cache de forma preventiva - ele só os coloca lá após um cliente criar um encadeamento e desconectar. Se você nunca tiver clientes X conectados ao mesmo tempo, você nunca terá threads X no cache:
When a client disconnects, the client's threads are put in the cache
if there are fewer than thread_cache_size threads there. (source)
Veja também esta resposta de Michael:
Setting thread_cache_size to a value larger than max_connections seems
like tremendously unhelpful advice... the cache can't possibly grow
larger than max_connections and even a cache anywhere close to that
size could only make sense if you have a tremendous amount of churn on
your threads... which, in a well-behaved application, won't be the
case.
link