搜尋本站文章

2010-11-15

在 SQL Server 上,是否該停用「超執行緒(HT,Hyper-Threading」?

筆者整理了以下的討論,作為各位的參考依據:

在「Microsoft SQL Server 2008 Tuning Tips for PeopleSoft Applications」一文中,提到以下的描述:
Hyper-threading is Intel’s implementation of simultaneous multithreading technology. 
The performance benefits of using hyper-threading are dependent upon workload. 

For PeopleSoft applications, it is recommended that you disable hyper-threading for the database server via the BIOS as our lab testing has shown little or no improvement.


Be aware: To Hyper or not to Hyper 一文中提到:
需要依據工作負載、使用的硬體設備,以及執行的作業方式等,經過測試後來決定是否停用 「超執行緒(HT,Hyper-Threading」。
Great! The experiment confirms the theory. So does it mean you have to disable HT when using SQL Server? 
The answer is it really depends on the load and hardware you are using. 
 
You have to test your application with HT on and off under heavy loads to understand HT's implications. 
Keep in mind that not only lazywriter thread can cause slowdown but any thread that performs large memory scan - for example a worker thread that scans large amount of data might be a culprit as well. 
For some customer applications when disabling HT we saw 10% increase in performance. 

So make sure that you do your home work before you decide to hyper on not to hyper :-)


Course 2786B: Designing a Microsoft SQL Server 2005 Infrastructure 中提到:
Hyperthreading allows a CPU to execute multiple threads simultaneously. 
Consequently, the CPU throughput increases. 
A CPU that supports hyperthreading contains two architectural states on a single physical core. 

Each state acts as a logical CPU for the operating system. 
However, the two logical CPUs use the same execution resources, so you do not get the performance benefits of using two physical CPUs.

以及以下的描述:
4. Is hyperthreading beneficial for a database server? Why or why not?
Answers will vary. 
Under certain conditions, the performance of a database server may improve if hyperthreading is enabled. 
However, a hyperthreaded CPU is not as effective as a dual core CPU or two individual CPUs.


摘錄與整理胡百敬老師 在 SQL Server 似乎因 Hyperthreading 誤判 一文內的建議:
今天看到 MVP 的 mailing list 中討論,就微軟的回答,似乎 Hyperthreading 只適用於 OLTP 大量使用者存取,但其語法都很簡單的情況。

若 OLTP 單一 batch 很複雜,或是 DW/DSS/OLAP 以分析為主,需要大量平行運算的的工作,最好都使用實體的 CPU 數(不是主機板上的 socket 數),其理由為:SQL Server 以所有的 CPU 運算力都相同為前提,設計平行計畫。但 Hyperthreading 的 CPU 並非如此。其建議是:

•在語法上採用 MAXDOP <實體 CPU 數>。 
•可以針對連接透過 Resource Governer 設定 CPU 數,但非所有版本的 SQL Server 都能使用這項功能。 
當然,也可以透過執行個體的 max degree of parallelism 設定

KB 322385 超執行緒的環境中的 SQL Server 支援(SQL Server support in a hyper-threaded environment) 一文討論如下:

Performance
The performance of hyper-threaded environments varies. 
Conservative testing has shown 10 to 20 percent gains for SQL Server workloads, but the application patterns have a significant affect. 

You might find that some applications do not receive an increase in performance by taking advantage of hyper-threading. 
If the physical processors are already saturated, using logical processors can actually reduce the workload achieved.

For example, applications that cause high levels of contention can cause decreased performance in a hyper-threaded environment. 
We recommend that you test your application thoroughly to make sure that a hyper-threaded environment provides you the performance gain that you want versus the purchase of equivalent physical CPUs. Hyper-threading can be very helpful but hyper-threading cannot replace the full power of an additional physical CPU.





以下資料摘錄自「超執行緒 - 维基百科」一文:

Intel Core i7 系列的 CPU 支援超執行緒的技術,令到四核心的處理器,有總共8個執行緒(2010年推出的Core i7 980X 6核心系列將有12個執行緒)。

超執行緒(HT, Hyper-Threading)是英特爾所研發的一種技術,於2002年發佈。
超執行緒技術原先只應用於Xeon處理器中,當時稱為“Super-Threading”。之後陸續應用在Pentium 4中,將技術主流化。

運作方式
每個單位時間內,CPU只能處理一個執行緒,以這樣的單位進行,如果想要在單位時間內處理超過一個的執行緒,是不可能的。
除非是有兩個核心處理單元,英特爾的HT技術便是以單個核心處理單元,去整合兩個邏輯處理單元,也就是一個實體核心,兩個邏輯核心,在單位時間內處理兩個執行緒,模擬雙核心運作。

顧慮
由於處理器實際上只有一個核心,能夠提升的效能約為5~15%左右,且萬一發生資源互搶的情形時,整體效能反而會下拉。
這亦是AMD不提供虛擬雙核心處理器的理由。

另外,由於架構的不同,AMD的處理器對多工處理的表現會較好,所以沒有迫切性令產品支援相關的技術。

要令到電腦支持超執行緒技術,必須要軟體和硬體的配合。
處理器本身要支援超執行緒,晶片組亦要支援相關處理器。

為此,當時的Intel推出了新的晶片組,i865PE和i875P。
要充分發揮超執行緒的效能,使用者要使用Windows 2000之後的作業系統,而Windows XP家用版亦同樣支援超執行緒技術。

除了微軟的Windows外,Linux kernel 2.4.x亦開始支援該技術。
軟體方面,不是所有程式都可以發揮超執行緒,通常優化了多處理器的程式都可以支援到。

此類軟體通常是图形或视频处理軟體。早期,遊戲軟體的支援是比較少。
但隨著多核心技術的普及,愈來愈多遊戲軟體支援多線程的處理器。


參考文件:
Microsoft SQL Server 2008 Tuning Tips for PeopleSoft Applications
http://download.microsoft.com/download/E/C/5/EC567749-20C0-4DC5-99B7-FA7C77A097EA/PeopleSoft%20on%20SQL%202008.docx

Performance Tuning Guidelines for Windows Server 2008 R2
http://www.microsoft.com/whdc/system/sysperf/Perf_tun_srv-R2.mspx

Be aware: To Hyper or not to Hyper
http://blogs.msdn.com/b/slavao/archive/2005/11/12/492119.aspx

The Perils of Hyperthreading for SQL Server
http://sqlblog.com/blogs/kevin_kline/archive/2007/08/18/the-perils-of-hyperthreading-for-sql-server.aspx

Course 2786B: Designing a Microsoft SQL Server 2005 Infrastructure
http://www.microsoft.com/learning/en/us/course.aspx?ID=2786B&locale=en-us

超執行緒的環境中的 SQL Server 支援 SQL Server support in a hyper-threaded environment
http://support.microsoft.com/kb/322385/zh-tw

--
社群討論:
Is it still recommended to disable hyperthreading on computers running SQL Server?
http://social.msdn.microsoft.com/Forums/en-US/sqlsetupandupgrade/thread/4180d5b8-f0ce-4d27-8e90-a5bc64c64ef2

SQL Server 2008 R2, Switch Hyperthreading and Turbo Mode On or Off?
http://social.msdn.microsoft.com/Forums/en-US/sqlsetupandupgrade/thread/24b98bde-3b59-4f69-b9ba-2d7d931f7008

MICROSOFT SQL SERVER PERFORMANCE TUNNING
http://netic.wordpress.com/2010/02/17/microsoft-sql-server-performance-tunning/

SQL 2008 Hyper-Threading Support
http://stevenrobert.wordpress.com/2009/11/11/sql-2008-hyper-threading-support/

SQL Server 似乎因 Hyperthreading 誤判
http://byronhu.wordpress.com/2010/10/16/sql-server-%E4%BC%BC%E4%B9%8E%E5%9B%A0-hyperthreading-%E8%AA%A4%E5%88%A4/

超執行緒 - 维基百科
http://zh.wikipedia.org/zh/%E8%B6%85%E5%9F%B7%E8%A1%8C%E7%B7%92

--
Intel® Hyper-Threading Technology (Intel® HT Technology)
http://www.intel.com/technology/platform-technology/hyper-threading/index.htm

超執行緒有損伺服器效能?
http://www.zdnet.com.tw/enterprise/topic/server/0,2000085723,20102668,00.htm

KB:954835_有多核心處理器電腦上您可能無法安裝 SQL Server 2005
在 Microsoft SQL Server 2008 中,不會發生這個問題。
http://support.microsoft.com/kb/954835