Threads_cached 0 while thread_cache_size > 0 I'm trying to little bit understand with some MySQL (in my case - MariaDB) performance.

One point I found - "threads caching".

So - I set:

thread_cache_size = 4


in my.cnf and restart server.

In status I see:

MariaDB [mysql]&gt; show status where variable_name like 'Threads%';
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| Threads_cached    | 0     |
| Threads_connected | 2     |
| Threads_created   | 23    |
| Threads_running   | 1     |
+-------------------+-------+
4 rows in set (0.00 sec)


Next - I run mysqlslap:

$ mysqlslap -v -u user -p --auto-generate-sql --concurrency=10 --number-of-queries=100
...
Number of clients running queries: 10
Average number of queries per client: 10


Thus, if I correct uderstood, after clients disconnected - server must save 4 thread in cache to use it later, but:

MariaDB [mysql]&gt; show status where variable_name='Threads_cached';
+----------------+-------+
| Variable_name  | Value |
+----------------+-------+
| Threads_cached | 0     |
+----------------+-------+
1 row in set (0.00 sec)


Threads_cached still have 0.
When a client disconnects, the client's threads are put in the cache if there are fewer than thread_cache_size threads there.


In your case, it would read


  When a client disconnects, the client's threads are put in the cache if there are fewer than 4 threads there.


Also, note the following from the MySQL Documentation


  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.


Given this statement, 4 would seem way too low. You should set it much higher or don't set it at all (letting MariaDB set it for you).