Mariadb Thread Pool VS Oracle MySQL Enterprise

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介:

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.)

 

 






本文转自 位鹏飞 51CTO博客,原文链接:http://blog.51cto.com/weipengfei/1163823,如需转载请自行联系原作者

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
5天前
|
Oracle 关系型数据库 MySQL
mysql数据库和Oracle的区别
mysql数据库和Oracle的区别
54 1
|
5天前
|
存储 Oracle 关系型数据库
oracle 数据库 迁移 mysql数据库
将 Oracle 数据库迁移到 MySQL 是一项复杂的任务,因为这两种数据库管理系统具有不同的架构、语法和功能。
24 0
|
5天前
|
SQL Oracle 关系型数据库
常用数据库的分页语句(mySQL、oracle、PostgreSQL、SQL Server)
常用数据库的分页语句(mySQL、oracle、PostgreSQL、SQL Server)
|
5天前
|
Oracle 关系型数据库 MySQL
数据库中对时间的操作(mySql、Oracle、pgSql)
数据库中对时间的操作(mySql、Oracle、pgSql)
|
5天前
|
分布式计算 关系型数据库 MySQL
oceanbase-oracle/mysql 如何导入数据
oceanbase-oracle/mysql 如何导入数据
|
5天前
|
Oracle 关系型数据库 MySQL
Seata常见问题之oracle 数据库 报 just support mysql如何解决
Seata 是一个开源的分布式事务解决方案,旨在提供高效且简单的事务协调机制,以解决微服务架构下跨服务调用(分布式场景)的一致性问题。以下是Seata常见问题的一个合集
63 0
|
5天前
|
SQL Oracle 关系型数据库
选择适合您网站的 SQL 托管:MS SQL Server、Oracle、MySQL 和 MS Ac
如果您希望您的网站能够存储和检索数据,您的Web服务器应该能够访问使用SQL语言的数据库系统。以下是一些常见的SQL托管选项:
53 1
|
5天前
|
SQL Oracle 关系型数据库
浅谈对数据库(MySQL、Oracle、SQL Server)的认识
浅谈对数据库(MySQL、Oracle、SQL Server)的认识
|
5天前
|
存储 Oracle 关系型数据库
百度搜索:蓝易云【oracle dblink mysql查询text无法显示问题】
通过使用 `DBMS_HS_PASSTHROUGH` 包执行 MySQL 查询并返回 CLOB 类型结果,可以解决 Oracle 数据库中无法直接显示 MySQL TEXT 类型数据的问题。
49 0
|
5天前
|
SQL Oracle 关系型数据库
选择适合您网站的 SQL 托管:MS SQL Server、Oracle、MySQL
如果您希望您的网站能够存储和检索数据,您的Web服务器应该能够访问使用SQL语言的数据库系统。以下是一些常见的SQL托管选项:
60 2

推荐镜像

更多