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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章