对两个相同的SQL Server进行相同的测试会导致不同的IO量

时间:2016-10-31 22:45:05

标签: sql sql-server performance sql-server-2014 difference

概述

我有两台具有相同硬件规格的服务器,应该配置相同。它们运行的​​Windows Server 2012 R2分别具有8个内核和128 GB RAM。在每台服务器上,我运行的是SQL Server 2014的Hyper-V实例。这些服务器当前没有做任何其他事情。

问题

当我在每台服务器上运行测试时,例如:

BULK INSERT LOADTEST_01 FROM 'E:\loadtest\data.dat' WITH ( DATAFILETYPE='native', BATCHSIZE=100000 )

一台服务器总是慢两倍(3分钟对6分钟)。吞吐量方面的实际表现是相同的,但是"慢" SQL Server生成大约两倍的I / O(读取和写入.mdf和.ldf),这导致测试需要更长的时间才能完成。

用于提取指标的查询是:

SELECT
[ReadLatency] =
    CASE WHEN [num_of_reads] = 0
        THEN 0 ELSE ([io_stall_read_ms] / [num_of_reads]) END,
[WriteLatency] =
    CASE WHEN [num_of_writes] = 0
        THEN 0 ELSE ([io_stall_write_ms] / [num_of_writes]) END,
[Latency] =
    CASE WHEN ([num_of_reads] = 0 AND [num_of_writes] = 0)
        THEN 0 ELSE ([io_stall] / ([num_of_reads] + [num_of_writes])) END,
[AvgBPerRead] =
    CASE WHEN [num_of_reads] = 0
        THEN 0 ELSE ([num_of_bytes_read] / [num_of_reads]) END,
[AvgBPerWrite] =
    CASE WHEN [num_of_writes] = 0
        THEN 0 ELSE ([num_of_bytes_written] / [num_of_writes]) END,
[AvgBPerTransfer] =
    CASE WHEN ([num_of_reads] = 0 AND [num_of_writes] = 0)
        THEN 0 ELSE
            (([num_of_bytes_read] + [num_of_bytes_written]) /
            ([num_of_reads] + [num_of_writes])) END,
LEFT ([mf].[physical_name], 2) AS [Drive],
DB_NAME ([vfs].[database_id]) AS [DB],
[mf].[physical_name]
FROM
sys.dm_io_virtual_file_stats (NULL,NULL) AS [vfs]
JOIN sys.master_files AS [mf]
ON [vfs].[database_id] = [mf].[database_id]
AND [vfs].[file_id] = [mf].[file_id]
-- WHERE [vfs].[file_id] = 2 -- log files
-- ORDER BY [Latency] DESC
-- ORDER BY [ReadLatency] DESC
ORDER BY [WriteLatency] DESC;
GO

指标(编辑以便于阅读):

Server DBName  Logicalnam  fileid Type physical nam             size     num_of_reads num_of_writes io_stall_read_ms io_stall_write_ms IO_Stall_Reads_PCT IO_Stall_Writes_PCt writes_and_reads mb_read mb_write reads_pct write_pct read_bytes_%  write_bytes_%
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
sql-01 PPTTemp PPTTemp     1      ROWS C:\DATA\PPTTemp.mdf      5000     117          13099         319              220298            0.1                 99.9               13216            6.89    3224.16     0.9       99.1          0.2       99.8
sql-01 PPTTemp PPTTemp_log 2      LOG  C:\DATA\PPTTemp_log.ldf  30131.63 54           223225        240              193244            0.1                 99.9               223279           1.14    12942.94    0         100           0         100
sql-02 PPTTemp PPTTemp     1      ROWS C:\DATA\PPTTemp.mdf      5000     108          7786          279              148597            0.2                 99.8               7894             6.59    1920.49     1.4       98.6          0.3       99.7
sql-02 PPTTemp PPTTemp_log 2      LOG  C:\DATA\PPTTemp_log.ldf  40105.25 57           174750        148              54018             0.3                 99.7               174807           1.16    10194.92    0         100           0         100

我尝试将同一个SQL Server虚拟机复制到两个物理主机服务器,但是"慢速"服务器继续生成更多的IO和"快速"服务器生成较少的IO。如果我消除任何网络和域成员资格,结果相同。

有人有想法吗?

我是关于重新彻底清除所有内容并从操作系统重新安装。我不明白Hyper-V主机如何使SQL Server虚拟机产生更多的IO,但我现在无法想到其他任何东西。

1 个答案:

答案 0 :(得分:0)

我敢打赌你的恢复模型和/或数据库值的初始大小在源和目标之间是不相同的。