当前位置:Gxlcms > 数据库问题 > mysql 自旋锁

mysql 自旋锁

时间:2021-07-01 10:21:17 帮助过:55人阅读

参数是自旋锁的轮转数,可以通过show engine innodb status来查看。相较于系统等待,自旋锁是低成本的等待;不过它是一个活跃的等待,会浪费一些cpu资源。因此如果看到大量的自旋等待和自旋轮转,则很显然它浪费了很多cpu资源。浪费cpu时间和无谓的上下文切换之间可以通过该值来平衡。

innodb_spin_wait_delay

    Vadim Tkachenko 在http://www.mysqlperformanceblog.com/2011/12/02/kernel_mutex-problem-or-double-throughput-with-single-variable/中对该参数进行了测试,并给出了结论。

    Peter Zaitsev在http://www.mysqlperformanceblog.com/2011/07/28/how-innodb-contention-may-manifest-itself/中也进行了解释在不同状况下,该值的影响。并在http://www.mysqlperformanceblog.com/2006/07/17/show-innodb-status-walk-through/中详细解释了show innodb status的输出进行了详细解释。

 

innodb_thread_concurrency

关于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 自旋锁

标签:

人气教程排行