thread_cahe_size线程池,线程缓存。用来缓存空闲的线程,以至于不被销毁,如果线程缓存中的空闲线程,需要重新建立新连接,则会优先调用线程池中的缓存,很快就能响应连接请求。
每建立一个连接,都需要一个线程与之匹配
MariaDB [(none)]> show global status like '%thread%';
+------------------------------------------+----------+
| Variable_name | Value |
+------------------------------------------+----------+
| Delayed_insert_threads | 0 |
| Innodb_master_thread_1_second_loops | 4338823 |
| Innodb_master_thread_10_second_loops | 432031 |
| Innodb_master_thread_background_loops | 18974 |
| Innodb_master_thread_main_flush_loops | 18974 |
| Innodb_master_thread_sleeps | 4338819 |
| Performance_schema_thread_classes_lost | 0 |
| Performance_schema_thread_instances_lost | 0 |
| Slow_launch_threads | 0 |
| Threadpool_idle_threads | 0 |
| Threadpool_threads | 0 |
| Threads_cached | 0 |代表当前此时此刻线程缓存中的空闲线程
| Threads_connected | 11 |代表当前建立的连接数
| Threads_created | 11032160 |最近一次服务启动以来,创建的线程数量
| Threads_running | 2 |当前激活的(非睡眠)的线程数
+------------------------------------------+----------+
thread_cache_size最好设置成和threads_connected一样。不过很少将thread_cache_size设置成比200大。
配置:
MySQL>set global thread_cache_size=30 即时生效
或者
vim /etc/my.cnf
thread_concurrency=30