14.6.6 Configuring Thread Concurrency for InnoDB

InnoDB uses operating system threads to process requests from user transactions. (Transactions may issue many requests to InnoDB before they commit or roll back.) On modern operating systems and servers with multi-core processors, where context switching is efficient, most workloads run well without any limit on the number of concurrent threads. Scalability improvements in MySQL 5.5 and up reduce the need to limit the number of concurrently executing threads inside InnoDB.
InnoDB使用操作系统线程处理来自用户事务的请求。(事务可能在提交或回滚之前向InnoDB发出许多请求。)在具有多核处理器的现代操作系统和服务器上,上下文切换效率很高,大多数工作负载运行良好,并且没有限制并发线程的数量。MySQL 5.5及以上版本的可伸缩性改进减少了对InnoDB内部并发执行线程数量的限制
In situations where it is helpful to minimize context switching between threads, InnoDB can use a number of techniques to limit the number of concurrently executing operating system threads (and thus the number of requests that are processed at any one time). When InnoDB receives a new request from a user session, if the number of threads concurrently executing is at a pre-defined limit, the new request sleeps for a short time before it tries again. A request that cannot be rescheduled after the sleep is put in a first-in/first-out queue and eventually is processed. Threads waiting for locks are not counted in the number of concurrently executing threads.
在某些情况下,最小化线程之间的上下文切换是很有帮助的,InnoDB可以使用许多技术来限制并发执行操作系统线程的数量(因此,可以限制在任何时候处理的请求的数量),当InnoDB收到来自用户会话的新请求时,如果并发执行的线程数量处于预定义的限制内,则新请求会在短时间内休眠,然后再次尝试。在休眠之后,不能重新调度的请求被放入一个先入/先出队列,并最终被处理。等待锁的线程不计入并发执行的线程数。
You can limit the number of concurrent threads by setting the configuration parameter innodb_thread_concurrency. Once the number of executing threads reaches this limit, additional threads sleep for a number of microseconds, set by the configuration parameter innodb_thread_sleep_delay, before being placed into the queue.
您可以通过设置配置参数innodb_thread_concurrent来限制并发线程的数量。一旦执行线程的数量达到这个限制,额外的线程就会休眠几微秒,具体时间由配置参数innodb_thread_sleep_delay设置,然后放入队列中
Previously, it required experimentation to find the optimal value for innodb_thread_sleep_delay, and the optimal value could change depending on the workload. In MySQL 5.6.3 and higher, you can set the configuration option innodb_adaptive_max_sleep_delay to the highest value you would allow for innodb_thread_sleep_delay, and InnoDB automatically adjusts innodb_thread_sleep_delay up or down depending on the current thread-scheduling activity. This dynamic adjustment helps the thread scheduling mechanism to work smoothly during times when the system is lightly loaded and when it is operating near full capacity.
在此之前,需要进行实验,以找到innodb_thread_sleep_delay的最优值,并且最优值可能会根据工作负载的不同而变化。在MySQL 5.6.3和更高版本中,您可以将配置选项innodb_adaptive_max_sleep_delay设置为innodb_thread_sleep_delay允许的最高值,innodb自动根据当前的线程调度活动调整innodb_thread_sleep_delay。这种动态调整有助于线程调度机制在系统轻载和接近满负荷运行时平稳运行。
The default value for innodb_thread_concurrency and the implied default limit on the number of concurrent threads has been changed in various releases of MySQL and InnoDB. The default value of innodb_thread_concurrency is 0, so that by default there is no limit on the number of concurrently executing threads.
innodb_thread_concurrency的默认值和并发线程数默认的默认限制在MySQL和InnoDB的各种版本中已经改变,innodb_thread_concurrency的默认值为0,因此默认情况下,并发执行线程的数量没有限制。
InnoDB causes threads to sleep only when the number of concurrent threads is limited. When there is no limit on the number of threads, all contend equally to be scheduled. That is, if innodb_thread_concurrency is 0, the value of innodb_thread_sleep_delay is ignored.
只有当并发线程数有限时,InnoDB才会导致线程休眠。 当线程数没有限制时,所有线程都同等地进行调度。。也就是说,如果innodb_thread_concurrency为0,则忽略innodb_thread_sleep_delay的值。
When there is a limit on the number of threads (when innodb_thread_concurrency is > 0), InnoDB reduces context switching overhead by permitting multiple requests made during the execution of a single SQL statement to enter InnoDB without observing the limit set by innodb_thread_concurrency. Since an SQL statement (such as a join) may comprise multiple row operations within InnoDB, InnoDB assigns a specified number of “tickets” that allow a thread to be scheduled repeatedly with minimal overhead.
当线程数量有限制时(当innodb_thread_concurrent> 0),InnoDB通过允许在执行单个SQL语句期间发出的多个请求进入InnoDB而不遵守innodb_thread_concurrency设置的限制来减少上下文切换开销。由于一个SQL语句(例如一个join)可能包含InnoDB内的多个行操作,所以InnoDB会分配指定数量的“tickets”,允许线程以最小的开销重复调度。
When a new SQL statement starts, a thread has no tickets, and it must observe innodb_thread_concurrency. Once the thread is entitled to enter InnoDB, it is assigned a number of tickets that it can use for subsequently entering InnoDB to perform row operations. If the tickets run out, the thread is evicted, and innodb_thread_concurrency is observed again which may place the thread back into the first-in/first-out queue of waiting threads. When the thread is once again entitled to enter InnoDB, tickets are assigned again. The number of tickets assigned is specified by the global option innodb_concurrency_tickets, which is 5000 by default. A thread that is waiting for a lock is given one ticket once the lock becomes available.
当一个新的SQL语句启动时,一个线程没有tickets,它必须观察innodb_thread_concurrency。一旦线程有资格进入InnoDB,它被分配了一些可以用于随后进入InnoDB来执行行操作的tickets。。如果tickets用完,线程被驱逐,并且再次观察innodb_thread_concurrency,这可能会将线程放回到等待线程的先入先出队列中。当线程再次有资格进入InnoDB时,将再次分配tickets。指定的tickets数量由全局选项innodb_concurrency_tickets指定,默认值为5000。一旦锁可用,等待锁的线程将获得一张ticket。
The correct values of these variables depend on your environment and workload. Try a range of different values to determine what value works for your applications. Before limiting the number of concurrently executing threads, review configuration options that may improve the performance of InnoDB on multi-core and multi-processor computers, such asinnodb_adaptive_hash_index.
这些变量的正确值取决于您的环境和工作负载。尝试一系列不同的值,以确定哪些值适合您的应用程序。在限制并发执行线程的数量之前,请检查可能提高多核和多处理器计算机InnoDB性能的配置选项,比如innodb_adaptive_hash_index。
For general performance information about MySQL thread handling, see Section 8.12.5.1, “How MySQL Uses Threads for Client Connections”.
有关MySQL线程处理的一般性能信息,请看Section 8.12.5.1, “How MySQL Uses Threads for Client Connections”.

PREV: 14.6.5.1Configuring the Change Buffer Maximum Size https://blog.51cto.com/itzhoujun/2356995
NEXT: 14.6.7 Configuring the Number of Background InnoDB https://blog.51cto.com/itzhoujun/2358044

上一篇:Julia 语言


下一篇:win10 无法修改默认程序 默认打开方式的解决方法