设为首页 收藏本站
查看: 1252|回复: 0

[经验分享] Mariadb Thread Pool VS Oracle MySQL Enterprise

[复制链接]

尚未签到

发表于 2018-9-23 14:56:55 | 显示全部楼层 |阅读模式
  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 阻挡 更多的短查询。
  

  
举例:
  

  
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
  

  
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的形式存在。
  测试数据:
  

  
taskset -c 0,1,2,3,4,5,6,7 ./sysbench --num-threads=100 --test=oltp --oltp-table-size=10000000 --mysql-table-engine=innodb --mysql-user=root --mysql-socket=/tmp/mariadb.sock --mysql-password=ws123 --mysql-db=test  --mysql-port=3308 run
  
sysbench 0.4.12:  multi-threaded system evaluation benchmark
  

  

  官方版本 未启用 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.)
  
    deadlocks:                           0      (0.00 per sec.)
  
    read/write requests:                 190000 (7260.16 per sec.)
  
    other operations:                    20000  (764.23 per sec.)



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-600356-1-1.html 上篇帖子: Oracle单引号和双引号 下篇帖子: Oracle RAC+ASM+DataGuard配置
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表