zoukankan      html  css  js  c++  java
  • MySQL学习笔记-数据库后台线程

    数据库后台线程

    默认情况下讲述的InnoDB存储引擎,以后不再重复声明。后台线程有7个——4个IO thread,1个master thread,1个锁监控线程,1个错误监控线程。IO thread的数量由配置文件中的innodb_file_io_threads参数控制,默认为4。4个IO线程分别是insert buffer thread、log thread、read thread、write thread。

    在MySQL 5.6.10中,MySQL企业版MySQL的包括线程池,使用服务器插件来实现。在MySQL服务器的默认线程处理模型使用执行每个客户端连接一个线程语句。随着越来越多的客户端连接到服务器和执行语句,整体性能降低。线程池插件提供旨在减少开销,提高性能的其他线程的处理模式。该插件实现了通过有效地管理语句执行线程的大量客户端连接的提高服务器性能的线程池。

    InnoDB Plugin版本开始增加了默认IO thread的数量,默认的read thread和write thread分别增大到了4个,并且不再使用innodb_file_io_threads参数,而是分别使用innodb_read_io_threads和innodb_write_io_threads参数。
    线程池解决每个连接模型解决单线程的几个问题:(原话也在其中,怕翻译错了。)
    • 过大的线程堆栈导致处理器高速缓存在高并发工作负载下几乎是无用。线程池促进线程堆栈重用,以尽量减少处理器高速缓存。
    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.
    • 伴随着过多的线程并发调用,上下文切换带来大量的性能消耗。与此同时对于操作系统任务调度也是富有挑战的任务。线程池控制着活跃线程数,以确保MySQL服务器内部保持高并发状态,同时操控并使服务器适应MySQL的运转。
    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.
    • 并发执行导致过多的事务竞争资源。在InnoDB中,导致了花在互斥的时间增加。一旦事务开启,线程池将控制不会有太多并发执行。
    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.
     

    Master thread在主循环中,分两大部分操作,每秒钟的操作每10秒钟的操作

    每秒一次的操作包括:

    1、日志缓冲刷新到磁盘,即使这个事务还没有提交(总是),这点解释了为什么再大的事务commit时都很快;

    2、合并插入缓冲(可能),合并插入并不是每秒都发生,InnoDB会判断当前一秒内发生的IO次数是否小于5,如果是,则系统认为当前的IO压力很小,可以执行合并插入缓冲的操作。

    3、至多刷新100个InnoDB的缓冲池的脏页到磁盘(可能),这个刷新100个脏页也不是每秒都在做

    每10秒一次的操作包括:

    1、刷新100个脏页到磁盘(可能);

    2、合并至多5个插入缓冲(总是);

    3、将日志缓冲刷新到磁盘(总是);

    4、删除无用的undo页(总是);

    5、产生一个检查点(checkpoing);






  • 相关阅读:
    写给自己的话
    软件开发之技能梳理
    《创新者的窘境》读书笔记
    我的四年踩坑史以及思考
    认识问题和求解问题的一种思考框架
    《时间的秩序》读书笔记
    从JSON中自动生成对应的对象模型
    考考你:一道题引发的小思考
    哈!如果一生只如花样短暂
    使用正则表达式抽取所需文本
  • 原文地址:https://www.cnblogs.com/snifferhu/p/4736479.html
Copyright © 2011-2022 走看看