[SQL Server]性能排错之系统等待:WRITELOG
2010-12-08 17:06
190 查看
WRITELOG
Definition
When a SQL Server session waits on the WRITELOG wait type, it is waiting to write the contents of the log cache to disk where the transaction log is stored.To explain the process in more detail, assume a session starts a transaction that will perform several INSERT statements. While the data is being inserted, two actions occur:
The data page in the buffer cache is updated with the new data.
Data is written to the log cache which is a segment of memory used to record data that will be used for rolling back the transaction or be written to the log file.
This process continues until the transaction has completed (committed) at which time the data in the log cache is immediately written to the physical log file. When SQL Server is in the act of flushing the log cache to disk, the session will wait on the WRITELOG wait type.
Getting More Information
If sessions are consistently waiting on the WRITELOG wait type, review the following Perfmon data for signs of disk bottlenecks where the transaction log is stored:PhysicalDisk Object
Avg. Disk Queue Length – the average number of IO requests that were queued. If this is consistently greater than one, this could indicate a disk bottleneck.
Avg. Disk sec/Read and Avg. Disk sec/Write – if either of these are higher than 15-20 ms, this could indicate the transaction log is stored on a slow device
SQLServer: Buffer Manager
Checkpoint pages/sec – number of pages flushed by checkpoint operations that require all dirty buffers to be written to disk
Using Ignite for SQL Server or other tools, also determine the top SQL statements waiting on the WRITELOG event. If many statements are found waiting, this could indicate that one of the above items is the problem. If only a few SQL statements are found waiting on WRITELOG, it could indicate an inefficient use of transactions (discussed with examples below).
Fixing the Problem
Disk Subsystem Performance - In much of the documentation about the WRITELOG wait type, it seems the problem is often mischaracterized as solely a disk subsystem issue. In the cases where disks are the problem, counters from the PhysicalDisk Object in Perfmon will be high and fixes often include:Adding additional IO bandwidth to the disk subsystem where the transaction log is stored.
Moving non-transaction log IO from the disk.
Moving the transaction log to a less busy disk.
Reducing the size of the transaction log has also helped in some cases.
Committing Data Too Often - In many cases that we see during performance consultations, excessive waits on the WRITELOG wait type can be caused by an over zealous usage of transactions, i.e. committing data too often. To illustrate this problem, consider the following code examples:
Example 1: The following code took 418 seconds to execute and waited 410 seconds on the WRITELOG wait type. Note how the COMMIT statement is located inside the loop and executed 100,000 times.
DECLARE @i INT SET @i = 1 WHILE @i < 100000 BEGIN BEGIN TRANSACTION INSERT INTO [splendidCRM].[dbo].[product] ([productid], [category], [name], [descn]) VALUES (@i, floor(@i / 1000), 'PROD' + REPLACE(str(@i),' ',''), 'PROD' + REPLACE(str(@i),' ','')) SET @i = @i + 1 COMMIT END | ||
DECLARE @i INT SET @i = 1 BEGIN TRANSACTION WHILE @i < 100000 BEGIN INSERT INTO [splendidCRM].[dbo].[product] ([productid], [category], [name], [descn]) VALUES (@i, floor(@i / 1000), 'PROD' + REPLACE(str(@i),' ',''), 'PROD' + REPLACE(str(@i),' ','')) SET @i = @i + 1 END COMMIT | ||
Conclusion
When sessions are found waiting on the WRITELOG wait type, it is imperative to perform a full analysis of the situation. This analysis should include review of disk performance data but also a review of all SQL statements found waiting on WRITELOG. Only then can you be assured you are solving the correct problem and not just adding expensive hardware that will not fix the root cause.相关文章推荐
- SQL Server 性能调优(一)——从等待状态判断系统资源瓶颈
- sql server性能分析--定时收集系统运行情况
- SQL Server--系统监视与性能调整--监视工具有SQL server活动监视器、性能监视器、SQL Server profiler
- SQL Server 性能调优(一)——从等待状态判断系统资源瓶颈
- 好文章——SQL Server应用模式之OLTP系统性能分析
- SQL Server 2005 重装时报:对性能监视器计数器注册表值执行系统配置检查失败
- SQL Server应用模式之OLTP系统性能分析
- SQL Server 性能调优(一)——从等待状态判断系统资源瓶颈
- 解决方法:对性能监视器计数器注册表值执行系统配置检查失败。有关详细信息,请参阅自述文件或 SQL Server 联机丛书中的“如何在 SQL Server 2005 中为安装程序增加计数器注册表项值”
- sql server 性能调优 资源等待之PAGEIOLATCH
- SQL Server性能优化——等待——SLEEP_BPROOL_FLUSH
- sql server性能分析--定时收集系统运行情况
- SQL Server--系统监视与性能调整
- sql server 性能调优 资源等待之 LCk
- 优化SQL SERVER系统性能
- SQL Server 性能调优(一)——从等待状态判断系统资源瓶颈
- sql server 性能调优 资源等待之内存瓶颈的三种等待类型
- sql server 性能调优 资源等待之网络I/O
- SQL Server 2005 重装时报:对性能监视器计数器注册表值执行系统配置检查失败 (转载)
- SQL Server 性能调优(一)——从等待状态判断系统资源瓶颈