zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    10 个非常有用的 AngularJS 框架
    15个最新加速 Web 开发的框架和工具
    最新13个加速 Web 开发的框架和工具
    7款个性化jQuery/HTML5地图插件
    19款绚丽实用的jQuery/CSS3侧边栏菜单
    7 个顶级的 HTML5 Canvas 动画赏析
    10款精美的web前端源码的特效
    10款web前端基于html5/CSS3应用特效
    8个强大的基于Bootstrap的CSS框架
    7款经典炫酷的HTML5/jQuery动画应用示例及源码
  • 原文地址:https://www.cnblogs.com/gaogao67/p/10637439.html
Copyright © 2011-2022 走看看