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

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

线程池对性能影响

MySQL--线程池(Thread Pool)

MySQL--线程池(Thread Pool)

参考链接:

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

上一篇:有向连通图增加多少边构成强联通(hdu3836,poj1236)


下一篇:手机端页面在项目中遇到的一些问题及解决办法