標籤:mysql 線程池 thread_cache_size 調優
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
重啟mysql。
mysql線程緩衝thread_cache_size參數最佳化