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. HanLP自然语言处理包介绍

    支持中文分词(N-最短路分词.CRF分词.索引分词.用户自定义词典.词性标注),命名实体识别(中国人名.音译人名.日本人名.地名.实体机构名识别),关键词提取,自动摘要,短语提取,拼音转换,简繁转换, ...

  2. javascript进阶笔记(1)

    学习js已经有一段时间了,大大小小还是能够做出一些东西来.不过觉得可惜的是,还是对js本身这门语言不是很熟悉,总有一点雾里看花的感觉,看得见,但是看不清楚.最近发现有一本关于js的叫做<忍者秘籍 ...

  3. vue-12-渲染函数 & JSX

    render() Vue.component('anchored-heading', { render: function (createElement) { return createElement ...

  4. freemarker学习 (servlet + freemarker -> Struts2+freemarker -> springMVC+freemarker)

    什么是freemarker? freemarker类似于jsp,但不是jsp!怎么说呢?freemarker文件后缀是.ftl,它不像jsp本质是servlet,它将构建模板.解析模板.使用模板分离开 ...

  5. 四川省赛 SCU - 4438

    Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text pp. Her j ...

  6. 关于时间戳截取的隐藏bug

    之前写时间戳,要截取后六位 原写法: function timeStamp() { const date = new Date() const month = date.getMonth() + 1 ...

  7. 使用std::map和std::list存放数据,消耗内存比实际数据大得多

    使用std::map和std::list存放数据,消耗内存比实际数据大得多 场景:项目中需要存储一个结构,如下程序段中TEST_DATA_STRU,结构占24B.但是使用代码中的std::list&l ...

  8. kbmMW 5.07.00试用笔记

    在kbmMW 5.06.20试用笔记中遇到的问题,在这个版本中,基本都解决了.但还是发现修正后存在的小问题及新问题: 1.Resolve返回值错误 当提交的ClientQuery是执行一条sql语句, ...

  9. 前端笔记 (1.HTML)

    近来一直在学习一些web的知识,主要是包括html,css,js和php,记录一下笔记,希望向和我一样刚学的朋友能提供帮助 这些笔记知识主要来源于菜鸟教程和w3school.我搭建了一个wampSer ...

  10. React native Configuration with name 'default' not found.

    添加插件后出现异常 FAILURE: Build failed with an exception. * What went wrong: A problem occurred configuring ...