Thread_pool_stall_limit:对于 long-running statement 和 被blocked 的语句 有很大的影响。对于blocked的情况,如果thread pool 能检测到则会开启一个新的线程,针对thread pool 没有检测到该情况,只能通过 该参数来设置超时时间。
该值太高的话,会出现 long-running 的statement 阻挡 更多的短查询。
举例:
When a statement arrives, what is the maximum time it can be delayed before it actually starts executing? Suppose that the following conditions apply:
· There are 200 statements queued in the low-priority queue.
· There are 10 statements queued in the high-priority queue.
· thread_pool_prio_kickup_timer is set to 10000 (10 seconds).
· thread_pool_stall_limit is set to 100 (1 second).
In the worst case, the 10 high-priority statements represent 10 transactions that continue executing for a long time. Thus, in the worst case, no statements will be moved to the high-priority queue because it will always already contain statements awaiting execution. After 10 seconds, the new statement is eligible to be moved to the high-priority queue. However, before it can be moved, all the statements before it must be moved as well. This could take another 2 seconds because a maximum of 100 statements per second are moved to the high-priority queue. Now when the statement reaches the high-priority queue, there could potentially be many long-running statements ahead of it. In the worst case, every one of those will become stalled and it will take 1 second for each statement before the next statement is retrieved from the high-priority queue. Thus, in this scenario, it will take 222 seconds before the new statement starts executing.
This example shows a worst case for an application. How to handle it depends on the application. If the application has high requirements for the response time, it should most likely throttle users at a higher level itself. Otherwise, it can use the thread pool configuration parameters to set some kind of a maximum waiting time.
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
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 不会限制最小的并发事务。