Oracle MySQL Enterprise 部分
Thread_pool_algorithm:
連接配接并發排程算法,預設值0 使用一種保守低級别并發的算法,經測試表現結果不錯。 值為1的話,并發數量會增大,采用更激進的算法性能,線上程數量一定的時候性能得到5-10%的提升,随着更大的連接配接數,性能會随之下降。
Thread_pool_high_priority_connection:
該參數影響 如何安排語句的執行順序,預設值為0,statement會使用 low priority 和 high-priority 兩種隊列,如果等于1的話,那隻會使用high priority 一種隊列。
Thread_pool_prio_kickup_timer:
statement 從low priority 隊列 移到 high-priority的等待時間。機關為毫秒
Thread_pool_max_unused_threads
該參數限制了sleep thread 所使用的記憶體。預設值為0,即不限制,當值為N時(N>1),1個 consumer thread ,n-1 個 reserve threads。當處于sleeping 的thread 達到最大值,再有新的thread 将要 sleep 的時候,該線程隻能直接退出。
一個sleeping thread 有兩種角色 consumer 和 reserve ,thread pool隻允許一個線程是 consumer thread,如果 有一個thread 将要sleep而此時 thread pool 中沒有 consumer角色的線程,那該線程會成為 consumer thread;當需要喚醒某個線程的時候,consumer thread是首選,隻有當consumer thread 這種角色的 線程不存在時 才會選擇 reserve 角色的線程
Thread_pool_size :thread groups的數量
Thread_pool_stall_limit:thread執行下一個新的 statement的時間間隔。
參數推薦配置:
Thread_pool_size 隻讀的變量,
主要的存儲引擎是:InnoDB, 取值為 16---36 最佳取值為 24---36 對于寫密集型的應用,有時候要 低于 36.
主要的存儲引擎是:MyISAM:最佳為 4—8,設定的太高 對性能沒有顯著的影響。
Thread_pool_stall_limit:對于 long-running statement 和 被blocked 的語句 有很大的影響。對于blocked的情況,如果thread pool 能檢測到則會開啟一個新的線程,針對thread pool 沒有檢測到該情況,隻能通過 該參數來設定逾時時間。
該值太高的話,會出現 long-running 的statement 阻擋 更多的短查詢。
舉例:
MariaDB部分
在mariadb 中使用 threadpool (以Linux為主)
在配置檔案中添加:thread_handling=pool-of-threads
Threadpool server variables 都是可以動态調整的。
在unix上推薦的參數:
Thread_pool_size 建議采用預設
Thread_pool_stall_limit;毫秒機關,預設值500 (0.5s)當達到這種限制的時候 threadpool會wake up 或者建立一個新的thread來執行新的statement,這種搶占機制哪種long-running query 霸占 這個pool,臨時允許多個線程并行執行,當線程的總量達到 thread_pool_max_threads 規定的總量時,就不會建立新的線程,甚至時間已經超過了thread_pool_stall_limit規定的時間。
Thread_pool_max_threads:預設值為500
Thread_pool_idle_timeout:預設60s空閑的線程退出時間間隔
Thread_pool_oversubscribe:預設值為3,這是對讓每個CPU都有超過1個同時運作的線程與讓線程sleep awake 的折中,值越高,會同時運作很多的線程,值越低,會出現更多的sleep 和 wake up
監控 thread pool 的狀态;
Thread_threads pool 目前的線程數
Threadpool_idle_threads :目前不活躍的線程數,隻涉及到unix,處于idle的狀态:wait for new work,blocked due to disk io,row or table lock
Troubleshooting blocking situations
盡管講 thread_pool_max_threads 調的很高,遇到全局鎖的情況可能會導緻整個pool 被block,假設一種情況 一個client 執行:flush tables with read lock 并暫停,此時有500個其他的client進行write操作, 最大線程數已經達到,此時在也不能執行 unlock table操作。
針對上述情況,mariadb 允許你使用專用的連接配接,并且設定 extra_port(不等于一般連接配接的 port),連接配接後可以增加 thread_pool_max_threads 或者kill 掉不必要的連接配接。
這裡需要在配置檔案中添加如下兩項:
Extra-port=0 (預設為0)
Extra-max-connections=1 (預設為1)
當extra-port >0的時候,可以進行super user 的連接配接,連接配接方式使用的是one-thread-per-connection method.
Mysql --port=’number-of-extra-port’ --protocol=tcp
MariaDB threadpool vs Oracle MySQL Enterprise Threadpool
相似地方:
1、 兩者同樣會将client connections 分組,thread_pool_size 都代表 thread group的個數,
2、 兩者對于thread stalls 使用相似的 schema checking。隻是機關不一緻, MariaDB使用的是毫秒,官方使用的是 10ms。
不同點:
1、 windows的實作方式完全不同,MariaDB 使用windows本地的 threadpool,oracle 使用WSAPoll() 方法來實作。而且對于管道或者共享記憶體連接配接是不起作用的
2、 MariaDB使用最有效的I/O multiplexing facilities 對于每一個os,windows(the I/O completion port is used internally by the native threadpool),linux(epoll),Solaris(event port),FreeBSD 和 OSX(kevent),Oracle 隻對linux 使用 epoll,其他的全部是 poll()
3、 相比于Oracle MySQL Enterprise,MariaDB threadpool 不會限制最小的并發事務。
4、 MariADB是 嵌入到server内,不是以plugin的形式存在。
測試資料:
官方版本 未啟用 threadpool
transactions: 10002 (298.79 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 190038 (5676.92 per sec.)
other operations: 20004 (597.57 per sec.)
mariadb 啟用 threadpool:
transactions: 10000 (382.11 per sec.)
read/write requests: 190000 (7260.16 per sec.)
other operations: 20000 (764.23 per sec.)
本文轉自 位鵬飛 51CTO部落格,原文連結:http://blog.51cto.com/weipengfei/1163823,如需轉載請自行聯系原作者