关于innodb_thread_concurrency参数 并发控制
http://dev.mysql.com/doc/refman/5.5/en/innodb-parameters.html#sysvar_innodb_thread_concurrency
Command-Line Format --innodb_thread_concurrency=#
Option-File Format innodb_thread_concurrency
Option Sets Variable Yes, innodb_thread_concurrency
Variable Name innodb_thread_concurrency
Variable Scope Global
Dynamic Variable Yes
Permitted Values
Type numeric
Default 0
Range 0 .. 1000
InnoDB tries to keep the number of operating system threads concurrently inside InnoDB less than or equal to the limit given by this variable. Once the number of threads reaches this limit, additional threads are placed into a wait state within a FIFO queue for execution. Threads waiting for locks are not counted in the number of concurrently executing threads.
The correct value for this variable is dependent on environment and workload. Try a range of different values to determine what value works for your applications. A recommended value is 2 times the number of CPUs plus the number of disks.
The range of this variable is 0 to 1000. A value of 0 (the default) is interpreted as infinite concurrency (no concurrency checking). Disabling thread concurrency checking enables InnoDB to create as many threads as it needs.
参数的含义是: InnoDB内部的并发线程数.
可以动态修改
具体解析: InnoDB 试图保持InnoDB内部的并发操作系统的线程数少于innodb_thread_concurrency设置的值
如果innodb并发线程数快要到达innodb_thread_concurrency=x,其他的innodb线程会被设置为等待状态,队列的算法是FIFO
处于等待拿锁状态的线程数,不会被计算入正在执行的并发线程数
innodb_thread_concurrency=x,x该设怎样的值,视服务器配置和服务器的负载情况。
默认推荐的值是 (cpu的数量+磁盘数量)x2 (我的理解,对于raid10的磁盘阵列,应该是磁盘总数/2)
参数取值范围 0-1000 当为默认值的时候,不是说0个并发线程。 而是被解释为无限并发(没有并发检查)
当innodb_thread_concurrency=0的时候,可以理解为 禁用线程并发检查,使InnoDB按照请求的需求, 创造尽可能多的线程.
http://www.dbathink.com/2012/10/trouble-shooting-the-high-sys-cpu-in-mysql-server/
并发控制
并发控制点:
-
- 并发控制的目的是最大化提高系统的资源利用率,并减少管理和调度开销。在MySQL实例中,主要处理sql请求,所以期望系统资源最大化提供给sql的执行过程。
sql的执行牵涉到server层和引擎层:
-
- 1. server层:比如cost计算,生成sql执行计划的过程
- 2. Innodb层:比如根据执行计划,查找和更新数据page的过程
所以在MySQL实例中,有两个最佳的并发控制点:
-
- 1. server层:sql开始执行时。 MySQL在5.6后,在server层引入了thread pool进行并发控制
- 2. Innodb层:记录查找和记录更新时。 Innodb存储引擎,使用innodb_thread_concurrency参数进行并发控制
并发控制大小:
-
- 设置过大:造成系统调度消耗过大
- 设置过小:不能完全的使用系统资源,造成资源浪费
经验值:# Try number of CPU's*2 for thread_concurrency
但还需要配合具体的平台和业务系统进行测试,才能找到最佳值。
Innodb并发控制
Innodb使用参数innodb_thread_concurrency控制并发线程的个数,源码中使用一对函数:
-
- innodb_srv_conc_enter_innodb
- innodb_srv_conc_exit_innodb
Innodb实现语句级的并发控制,在语句执行结束,stmt commit的时候,强制释放资源。
权衡和优化
- 1. 一方面进行并发控制,提高资源利用率,
- 2. 另一方还需要控制调度公平,防饿死等。
Innodb引入了n_tickets_to_enter_innodb参数,sql进入innodb执行时进行初始化,默认值500。
在执行过程中,依次进行递减,递减到0时,强制退出并发线程,重新抢占。
好处:
-
- 1. 一方面单条sql可能写入或者更新多条记录,节省每次enter innodb的线程抢占代价。
- 2. 另一方面防止单条sql过多的长时间占用并发线程,导致其它线程饿死的情况
关于innodb_thread_concurrency参数 并发控制的更多相关文章
- MySQL Innodb 并发涉及参数
1 参数作用 MySQL的各个插件式引擎中,都会对事务及线程做一定的处理和优化.在Innodb引擎中,总是尝试保持 innodb内 操作系统的线程数(暂命名为innodb_thread) 应该小于或等 ...
- MySQL InnoDB配置并发线程( innodb_thread_concurrency)
http://www.ywnds.com/?p=9821 一.thread_concurrency 首先,最重要的一点,这个参数已经在最新版本的MySQL中被移除了,官方最新5.7版本的doc上面对t ...
- MySQL thread pool【转】
本文来自:http://blog.chinaunix.net/uid-26896862-id-3993773.html 刚刚经历了淘宝的双11,真实感受到了紧张的氛围.尽管DB淡定的度过,但是历程中的 ...
- mysql 自旋锁
自旋(spin)是一种通过不间断地测试来查看一个资源是否变为可用状态的等待操作,用于仅需要等待很短的时间等待所需资源的场景.使用自旋这种“空闲循环(busy-loop)”来完成资源等待的方式要比通过上 ...
- mysql Inoodb 内核
MySQL从5.5版本开始将InnoDB作为默认存储引擎,该存储引擎是第一个完整支持事务ACID特性的存储引擎,且支持数据行锁,多版本并发控制(MVCC),外键,以及一致性非锁定读. 作为默认存储引擎 ...
- show engine innodb status 详细介绍
Contents Header1 SEMAPHORES. 1 LATEST DETECTED DEADLOCK. 3 TRANSACTIONS. 5 什么是purge操作... 5 FILE I/O. ...
- MySQL面试宝典
==============================================# 参数==============================================auto ...
- Mysql线程池优化笔记
Mysql线程池优化我是总结了一个站长的3篇文章了,这里我整理到一起来本文章就分为三个优化段了,下面一起来看看. Mysql线程池系列一(Thread pool FAQ) 首先介绍什么是mys ...
- 14.6.6 Configuring Thread Concurrency for InnoDB 配置线程并发
14.6.6 Configuring Thread Concurrency for InnoDB 配置线程并发 InnoDB 使用操作系统线程来处理请求(用户事务) 事务可能执行很多次在它们提交或者回 ...
随机推荐
- MySQL使用全文索引(fulltext index)---高性能
转载地址:https://blog.csdn.net/u011734144/article/details/52817766/ 1.创建全文索引(FullText index) 旧版的MySQL的全文 ...
- elasticsearch配置详解
一.说明 使用的是新版本5.1,直接从官网下载rpm包进行安装,https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5 ...
- PHP中输出本地时间
<?php header("Content-Type:text/html;charset=utf-8"); // 输出日 echo date("l") . ...
- URAL 1941
比赛的时候三个点没有优化成功.其实也没有想到哈希成数.然后就变成了只要一个长度和scary相等的区间内所有数字个数都是相等的.那么就是符合题意的.于是.为了不TLE我们不能对txt每个位置遍历 的同时 ...
- Openwrt Support RESET Button (5)
1 Scope of Document This document describes how to support reset button under openwrt system2 Requir ...
- POJ 1007 DNA sorting (关于字符串和排序的水题)
#include<iostream>//写字符串的题目可以用这种方式:str[i][j] &str[i] using namespace std; int main() {int ...
- rdf-3x简要使用
github下载地址:https://github.com/gh-rdf3x/gh-rdf3x rdf3x是用C++编写的,linux系统中,需要对其编译进行编译 1.安装g++编译器sudo apt ...
- centos7 sftp设置后 ssh 启动失败 原因分析
大多数人 在 设置SFTP 使用时,会在 ../sshd_config中添加如下内容: ------------------------------- Subsystem sftp internal- ...
- 网络编程(socket,套接字)
服务端地址不变 ip + mac 标识唯一一台机器 ip +端口 标识唯一客户端应用程序 套接字: 网络编程 网络编程 一.python提供了两个级别访问的网络服务 低级别的网络服务支持基本的 S ...
- About RFC
RFC说明 Request For Comments (RFC),是一系列以编号排定的文件,几乎所有的因特网标准都收录在RFC文件之中,如果你想成为网络方面的专家,那么RFC无疑是最重要也是最经常需要 ...