线程池是Mysql connection handler的一种区别于默认的per thread connection handler(每一个用户连接对应一个线程)thread pool通过一批分组的线程来服务用户连接
thread pool组成:
trhead group 线程组 分组管理
low priority queue 低优先级队列
high priority queue 高优先级队列
worker thread 工作线程 鉴权 处理用户请求
listener thread 监听用户连接 有新的请求到来时分发或者直接处理
核心参数:
thread_pool_enabled thread pool开关
thread_pool_size thread pool 的group数量
thread_pool_oversubscribe 每个group中最多的活跃线程数
thread_pool_max_threads 线程池中线程数量最大限制
thread 和connection的关系
thread pool中 用户连接,在开启thread pool的状态下,跟开启thread是多对多的关系,一个连接不同请求可能被不同的thread去处理,一个thread可能在不同的时间段处理不同的用户连接
如何判断connection进⼊⾼/低优先级队列?
- 根据参数thread_pool_high_prio_mode判断
TP_HIGH_PRIO_MODE_STATEMENTS, thread pool会认定所有请求为⾼优先级
TP_HIGH_PRIO_MODE_TRANSACTIONS, 显式事务内请求认定为⾼优先级
TP_HIGH_PRIO_MODE_NONE,判断当前连接是否持有MDL_EXPLICIT类型的元数据信息锁 - 根据参数thread_pool_high_priority_users, 认为这些⽤户的请求为⾼优先级
- 根据参数thread_pool_high_prio_handshake,开启后,新建连接在未鉴权时优先处理
- 根据参数threadpool_high_prio_maintain_conn,开启后所有maintain user会⾼优先级处理,这⾥
主要提供给管控使⽤。
COM_BINLOG_DUMP_GTID // binlog dump
COM_BINLOG_DUMP // binlog dump
COM_POLAR_LOG_DUMP // 物理复制相关
COM_POLAR_LOG_ACK // 物理复制相关
COM_RDS_PUSH_LSN // 代理监听lsn
这类线程不会占⽤thread pool中的活跃线程指标。
参考:
阿里云:https://help.aliyun.com/zh/polardb/polardb-for-mysql/user-guide/thread-pool?spm=a2c4g.11186623.0.i1
内核:https://www.bookstack.cn/read/aliyun-rds-core/81fed3723cd8562f.md