傳統 MySQL/MariaDB 採用「一連線一執行緒」模型,高併發下執行緒頻繁建立銷毀、CPU 切換開銷巨大。Thread Pool(線程池)技術透過固定數量的工作執行緒處理所有連線請求,有效解決此痛點。
Thread Pool 採用「執行緒代理模型」:
thread_pool_max_threads 控制)thread_pool_max_threads 硬性限制並發執行緒上限thread_pool_min_threads 仍會建立新執行緒,效果打折SELECT 1 這類輕量查詢,也需排隊等待可用執行緒,反而增加延遲在 my.cnf 的 [mysqld] 區段加入:
[mysqld] # 啟用 Thread Pool thread_handling=pool-of-threads # 可選微調參數 thread_pool_max_threads=500 thread_pool_min_threads=10 thread_pool_idle_timeout=60
目前支援 Thread Pool 的版本:
建議:生產環境啟用前務必進行壓測驗證,結合 thread_pool_stall_limit 等進階參數微調,避免因配置不當反而拖垮效能。