Mariadb Thread Pool VS Oracle MySQL Enterprise

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
RDS MySQL DuckDB 分析主实例,集群系列 8核16GB
简介:

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

相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。   相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情: https://www.aliyun.com/product/rds/mysql 
目录
相关文章
|
3月前
|
关系型数据库 MySQL 数据库
阿里云数据库RDS费用价格:MySQL、SQL Server、PostgreSQL和MariaDB引擎收费标准
阿里云RDS数据库支持MySQL、SQL Server、PostgreSQL、MariaDB,多种引擎优惠上线!MySQL倚天版88元/年,SQL Server 2核4G仅299元/年,PostgreSQL 227元/年起。高可用、可弹性伸缩,安全稳定。详情见官网活动页。
|
3月前
|
关系型数据库 分布式数据库 数据库
阿里云数据库收费价格:MySQL、PostgreSQL、SQL Server和MariaDB引擎费用整理
阿里云数据库提供多种类型,包括关系型与NoSQL,主流如PolarDB、RDS MySQL/PostgreSQL、Redis等。价格低至21元/月起,支持按需付费与优惠套餐,适用于各类应用场景。
|
3月前
|
关系型数据库 MySQL 数据库
阿里云数据库RDS支持MySQL、SQL Server、PostgreSQL和MariaDB引擎
阿里云数据库RDS支持MySQL、SQL Server、PostgreSQL和MariaDB引擎,提供高性价比、稳定安全的云数据库服务,适用于多种行业与业务场景。
|
8月前
|
Oracle 关系型数据库 MySQL
Oracle linux 8 二进制安装 MySQL 8.4企业版
Oracle linux 8 二进制安装 MySQL 8.4企业版
291 1
|
10月前
|
SQL Oracle 关系型数据库
MySQL 和 Oracle 的区别?
本文对比了Oracle和MySQL数据库的多个方面。Oracle适用于大型数据库,支持高并发和大访问量,市场占有率为40%,安装占用空间较大,约3G;而MySQL适合中小型应用,是开源免费的,安装仅需152M。两者在主键生成、字符串处理、SQL语句、事务处理等方面存在差异。Oracle功能更为强大,尤其在企业级应用中表现突出,而MySQL则以简单易用见长。
1194 7
MySQL 和 Oracle 的区别?
|
8月前
|
SQL 缓存 关系型数据库
MySQL8.4 Enterprise安装Firewall及测试
MySQL8.4 Enterprise安装Firewall及测试
247 0
|
9月前
|
Oracle 关系型数据库 MySQL
使用崖山YMP 迁移 Oracle/MySQL 至YashanDB 23.2 验证测试
这篇文章是作者尚雷关于使用崖山YMP迁移Oracle/MySQL至YashanDB 23.2的验证测试分享。介绍了YMP的产品信息,包括架构、版本支持等,还详细阐述了外置库部署、YMP部署、访问YMP、数据源管理、任务管理(创建任务、迁移配置、离线迁移、校验初始化、一致性校验)及MySQL迁移的全过程。
|
11月前
|
监控 Oracle 关系型数据库
Mysql、Oracle审计日志的开启
通过上述步骤,可以在 MySQL 和 Oracle 数据库中启用和配置审计日志。这些日志对于监控数据库操作、提高安全性和满足合规性要求非常重要。确保正确配置审计参数和策略,定期查看和分析审计日志,有助于及时发现并处理潜在的安全问题。
653 11
|
存储 关系型数据库 MySQL
MySQL vs. PostgreSQL:选择适合你的开源数据库
在众多开源数据库中,MySQL和PostgreSQL无疑是最受欢迎的两个。它们都有着强大的功能、广泛的社区支持和丰富的生态系统。然而,它们在设计理念、性能特点、功能特性等方面存在着显著的差异。本文将从这三个方面对MySQL和PostgreSQL进行比较,以帮助您选择更适合您需求的开源数据库。
609 4
|
Oracle NoSQL 关系型数据库
主流数据库对比:MySQL、PostgreSQL、Oracle和Redis的优缺点分析
主流数据库对比:MySQL、PostgreSQL、Oracle和Redis的优缺点分析
2516 3

推荐镜像

更多