天天看点

Mariadb Thread Pool VS Oracle MySQL Enterprise

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,如需转载请自行联系原作者