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. CKEditor编辑器的使用

    <div class="form-group" id="infolink-edier-div"> <label for="" ...

  2. FFT理解

     *连续时间-周期性信号频谱 clc;clear;close all N = input('N= '); T = 0.05; n = 1:N; %原始数据输入 D = 2*pi/(N*T); %计算分 ...

  3. ubuntu 搭建ss和使用方法

    一 ubuntu 搭建ssa.安装    sudo apt-get install python-gevent python-pip python-m2crypto    sudo pip insta ...

  4. static关键字(修饰函数、局部变量、全局变量)

    在C语言中,static的字面意思很容易把我们导入歧途,其实它的作用有三条. (1)先来介绍它的第一条也是最重要的一条:隐藏. 当我们同时编译多个文件时,所有未加static前缀的全局变量和函数都具有 ...

  5. oracle截取字段中的部分字符串

    使用Oracle中Instr()和substr()函数: 在Oracle中可以使用instr函数对某个字符串进行判断,判断其是否含有指定的字符. 其语法为: instr(sourceString,de ...

  6. ios初识UITableView及简单用法二(模型数据)

    // // ViewController.m // ZQRTableViewTest // // Created by zzqqrr on 17/8/24. // Copyright (c) 2017 ...

  7. for循环遍历改用map函数

    # for url in urls:# url = response.urljoin(url)# print(url)urls = map(lambda url:response.urljoin(ur ...

  8. tp5 生成缩略图片

    我先说下我的思路,先把正常图片存到服务器,再通过代码将服务器上的大图压缩,生成新的小图替代大图 下面上代码 前台HTML代码 <div class="upload-btn"& ...

  9. 简短而有效的python queue队列解释

    Queue.qsize() 返回队列的大小  Queue.empty() 如果队列为空,返回True,反之False  Queue.full() 如果队列满了,返回True,反之False Queue ...

  10. HTTPS双向认证+USB硬件加密锁(加密狗)配置

    环境:  Ubuntu14.04,apache2.4.7, openssl1.0.1f 安装apache2 apt-get install apache2 -y 一般openssl默认已经安装 开启a ...