MySQL--线程池(Thread Pool)

=================================================================

线程池技术

在MySQL社区版中,MySQL使用one-thread-per-connection的方式来处理数据库连接,即当MySQL客户端与服务器端建立连接时会创建一个线程来专门处理该连接的所有SQL请求。
one-thread-per-connection优缺点:

优点:
one-thread-per-connection方式实现简单,在连接数较少或使用长连接的场景中有保证较小的响应时间。

缺点:
在大量短连接或高并发场景下,one-thread-per-connection方式需要频繁地创建/销毁线程,并在大量线程间进行切换调度,产生较多的上线文切换(context-switch), 导致系统出现性能问题。

 

在MySQL企业版中,MySQL提供线程池特性,通过创建多个工作线程来共同处理所有连接的SQL请求,控制MYSQL内部线程数量,避免当连接过多时存储引擎创建大量线程,保证数据库在大并发的情况下保持稳定性和持续的吞吐能力。

MySQL线程池解决如下问题:

1、提升CPU Cache的有效率。
2、减少CPU 上线文切换(context-switch)。
3、减少InnoDB内部mutexes资源争抢。

Too many thread stacks make CPU caches almost useless in highly parallel execution workloads. The thread pool promotes thread stack reuse to minimize the CPU cache footprint.

With too many threads executing in parallel, context switching overhead is high. This also presents a challenging task to the operating system scheduler. The thread pool controls the number of active threads to keep the parallelism within the MySQL server at a level that it can handle and that is appropriate for the server host on which MySQL is executing.

Too many transactions executing in parallel increases resource contention. In InnoDB, this increases the time spent holding central mutexes. The thread pool controls when transactions start to ensure that not too many execute in parallel. 

https://dev.mysql.com/doc/refman/5.6/en/thread-pool.html

=================================================================

线程池对性能影响

参考链接:

http://www.gpfeng.com/?p=540&utm_source=tuicool&utm_medium=referral

https://blog.csdn.net/z69183787/article/details/52910079

https://blog.csdn.net/a19860903/article/details/52329636

 

转载于:https://www.cnblogs.com/gaogao67/p/10637439.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值