InnoDB并发线程控制

MySQL InnoDB存储引擎提供innodb_thread_concurrency来控制进入InnoDB 存储引擎的线程数,以限制InnoDB存储引擎层的并发量。

当innodb_thread_concurrency>0时,表示开启线程数检查机制,当有新的Mysql线程调用InnoDB接口前,InnoDB会检查已经接收的请求线程数量(处于等待锁状态的线程数量不被计算在内),如果数量超过innodb_thread_concurrency设置的限制,则会将该线程等待innodb_thread_sleep_delay微秒后,然后重新获取,如果第二次请求仍获取失败,会将该线程放入FIFO队列中休眠,在队列中等待处理。两次请求机制是为了避免线程被放到FIFO队列后又快速被取出处理,减少CPU的上下文却换的次数,降低CPU消耗。
参数innodb_thread_concurrency默认值为0,不进行限制

在MySQL 5.6.3版本后,可以通过参数innodb_adaptive_max_sleep_delay来动态调整innodb_thread_sleep_delay的值,以保障系统在低负荷或高负荷时顺利调度。
参数innodb_adaptive_max_sleep_delay默认值为150000,单位为微妙(microseconds)

当一个线程获得调用InnoDB接口权限时,会为该线程分配一个入场券(Ticket),在入场券失效前,该进行可以随时调用InnoDB接口而无需考虑当前请求线程数量。
在MySQL 5.6.5之前,参数值innodb_concurrency_tickets默认为500
在MySQL 5.6.6之后,参数值innodb_concurrency_tickets默认为5000

相关参数解释:

innodb_thread_concurrency:
InnoDB tries to keep the number of operating system threads concurrently inside InnoDB less than or equal to the limit given by this variable (InnoDB uses operating system threads to process user transactions). Once the number of threads reaches this limit, additional threads are placed into a wait state within a “First In, First Out” (FIFO) queue for execution. Threads waiting for locks are not counted in the number of concurrently executing threads. innodb_thread_sleep_delay:
Defines how long InnoDB threads sleep before joining the InnoDB queue, in microseconds. innodb_adaptive_max_sleep_delay:
Permits InnoDB to automatically adjust the value of innodb_thread_sleep_delay up or down according to the current workload. innodb_concurrency_tickets:
Determines the number of threads that can enter InnoDB concurrently. A thread is placed in a queue when it tries to enter InnoDB if the number of threads has already reached the concurrency limit. When a thread is permitted to enter InnoDB, it is given a number of “ tickets” equal to the value of innodb_concurrency_tickets, and the thread can enter and leave InnoDB freely until it has used up its tickets. After that point, the thread again becomes subject to the concurrency check (and possible queuing) the next time it tries to enter InnoDB.

innodb_thread_concurrency参数设置建议

官方建议:
当并发用户线程数量小于64时,建议将innodb_thread_concurrency设置0。
在大部分场景下,将innodb_thread_concurrency设置小于或等于逻辑CPU核数的值能获得最佳性能。 民间建议:
对于MySQL5.5及之前版本,建议将innodb_thread_concurrency设置在8至32之间。
对于MySQL5.6版本,建议将innodb_thread_concurrency设置为32。

其他

对于秒杀的场景,如果大量并发请求涌入MYSQL,虽然可以通过innodb_thread_concurrency来限制进入Innodb的存储引擎的线程数量,避免Innodb存储引擎耗费大量资源去处理锁等待和线程唤醒操作,但仍会导致MYSQL层次积压大量线程,消耗大量CPU资源来处理这些线程,从而拖慢秒杀性能。

MySQL--InnoDB并发线程控制的更多相关文章

  1. MySQL Innodb 并发涉及参数

    1 参数作用 MySQL的各个插件式引擎中,都会对事务及线程做一定的处理和优化.在Innodb引擎中,总是尝试保持 innodb内 操作系统的线程数(暂命名为innodb_thread) 应该小于或等 ...

  2. MySQL InnoDB配置并发线程( innodb_thread_concurrency)

    http://www.ywnds.com/?p=9821 一.thread_concurrency 首先,最重要的一点,这个参数已经在最新版本的MySQL中被移除了,官方最新5.7版本的doc上面对t ...

  3. 14.6.6 Configuring Thread Concurrency for InnoDB 配置线程并发

    14.6.6 Configuring Thread Concurrency for InnoDB 配置线程并发 InnoDB 使用操作系统线程来处理请求(用户事务) 事务可能执行很多次在它们提交或者回 ...

  4. Java并发1——线程创建、启动、生命周期与线程控制

    内容提要: 线程与进程 为什么要使用多线程/进程?线程与进程的区别?线程对比进程的优势?Java中有多进程吗? 线程的创建与启动 线程的创建有哪几种方式?它们之间有什么区别? 线程的生命周期与线程控制 ...

  5. Java--Semaphore控制并发线程数量

    package com; import java.util.concurrent.Semaphore; /** * Created by yangyu on 16/11/28. */ /** * Se ...

  6. MySQL InnoDB 实现高并发原理

    MySQL 原理篇 MySQL 索引机制 MySQL 体系结构及存储引擎 MySQL 语句执行过程详解 MySQL 执行计划详解 MySQL InnoDB 缓冲池 MySQL InnoDB 事务 My ...

  7. java并发编程基础—生命周期与线程控制

    一.线程生命周期 线程被创建启动以后,他既不是一启动就进入执行状态,也不是一直处于执行状态,在线程的生命周期中,它要经过新建(New).就绪(Runnable).运行(Running).阻塞(Bloc ...

  8. 浅谈mysql innodb缓存策略

    浅谈mysql innodb缓存策略: The InnoDB Buffer Pool Innodb 持有一个存储区域叫做buffer pool是为了在内存中缓存数据和索引,知道innodb buffe ...

  9. 搞懂MySQL InnoDB事务ACID实现原理

    前言 说到数据库事务,想到的就是要么都做修改,要么都不做.或者是ACID的概念.其实事务的本质就是锁和并发和重做日志的结合体.那么,这一篇主要讲一下InnoDB中的事务到底是如何实现ACID的. 原子 ...

随机推荐

  1. lnmp 基础设置

    1.设置ci.tp.laravel重写,去掉index.php location / { try_files $uri $uri/ /index.php?$query_string; } 2.开启ph ...

  2. 几大principal

    1.A class should have only one reason to change. 一个类只负责一件事 2.高层抽象不依赖低层实现

  3. [转]如何远程连接运行OpenGL/Cuda 等GPU程序

    发现一篇神文,解决了困扰许久的远程桌面OpenGL/GPU 等问题... 原地址在这:http://www.tanglei.name/how-to-run-gpu-programs-using-rem ...

  4. B2C B2B C2C O2O模式的介绍

                    b2c:天猫 商家对客户                 c2c:淘宝 客户到客户(卖家也是阿里公司的客户)                 o2o:美团 线上花费,下 ...

  5. kettle在linux下执行任务

    1.下载 最新版下载 7.1 https://community.hitachivantara.com/docs/DOC-1009855 准备 上传任务文件 .kjb,.ktr 上传mysql 驱动 ...

  6. SharePoint REST API - OData查询操作

    博客地址:http://blog.csdn.net/FoxDave 本篇主要讲述SharePoint REST中OData的查询操作.SharePoint REST服务支持很多OData查询字符串 ...

  7. TransactionScop事务机制的使用

    如果在C#中使用TransactionScope类(分布式事务),则须注意如下事项:1.在项目中引用using System.Transactions命名空间(先要在添加net组件的引用); 2.具体 ...

  8. Android:如何获取屏幕的宽高

    WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); DisplayMet ...

  9. Vue中 v-html 与 v-text 的区别

    解析的效果:

  10. ob 函数的使用

    ob 函数的使用1. 页面静态化 $id = isset($_GET['id'])?$_GET['id']-0:0; $filename = "html/".date(" ...