SQL Server 创建性能基线

本文涉及的产品
云数据库 RDS SQL Server,独享型 2核4GB
简介:

Creating a Performance Baseline - Part 1

You'll often hear that you should monitor the performance of SQL Server. You may read a little about performance monitoring, and you may turn on a few counters or perform a query against a dynamic management view that you know about. But, you may still wonder "Are these numbers good or bad?"

To determine if something is bad, you need to know what it looks like when it is good. Sounds obvious doesn't it? By creating a performance baseline, you can learn what your numbers are when your system is performing well. A performance baseline includes a single performance chart that is accompanied by an interpretation of the results, based on your environment.

To establish your performance baseline against Workforce Central, you'll need to find a time when the performance of your SQL Server environment is considered normal. For example, no users are complaining about slow responses, no backups or large jobs are running, and no "special" processing is taking place. Once you find that time, you'll need to collect a range of Windows Performance Monitor (perfmon) counters, information from dynamic management views, and maybe even a small SQL Server Profiler trace. Then, you can use the results of your collection as the starting point for subsequent performance collections. How do the new numbers compare to the baseline numbers, when everything was fine? Did one counter go up or down? Did several numbers change? Having something to compare the current numbers with can help you identify the source of new performance bottlenecks.

What Should You Monitor?

The actual counters, dynamic management views, or SQL Server Profiler trace events that you should collect are based on your system setup. But, the counters that we list below are a good place to start. If you capture these counters, you should have enough information to determine if you are having a performance issue—and if you are having an issue, which area is the source.

Note: Many of the counters that we list below list a threshold. These threshold numbers are not written in stone, and your actual values may be different. It is important to note that a standard threshold number is a starting point—if your value is a little higher or a little lower, the values that you see during your performance baseline collection become your new thresholds.

Monitoring the Disk Subsystem

There are several methods to monitor the disk subsystem. Since the disk subsystem is getting more and more complex each year, we recommend that database administrators monitor the following Performance Monitor counters to understand the latency of their disk I/O requests.

These two counters should provide you with enough information to determine if you have disk I/O bottlenecks. You should monitor these counters at both the host layer and the virtual server layer.

As with all performance monitoring, you should monitor on a continuous basis and then report daily or hourly, as your situation demands. This prevents nonpeak hours from watering down the peak-hour readings and distorting the performance measurements.

LogicalDisk(*): Avg. Disk Sec/Read.

This counter measures the average time, in seconds, of a read of data from the disk.

Thresholds:

· Less than 10 milliseconds (ms) = very good

· Between 10 and 20 ms = okay

· Between 20 and 50 ms = slow, needs attention

· Greater than 50 ms = serious I/O bottleneck

Note that Avg. Disk Sec/Read is a server-wide counter and therefore cannot be obtained through SQL Server 2005 dynamic management views.

LogicalDisk(*): Avg. Disk Sec/Write.

This counter measures the average time, in seconds, of a write of data to the disk.

Thresholds:

· Less than 10 ms = very good

· Between 10 and 20 ms = okay

· Between 20 and 50 ms = slow, needs attention

· Greater than 50 ms = serious I/O bottleneck

Note that Avg. Disk Sec/Write is a server-wide counter and therefore cannot be obtained through SQL Server 2005 dynamic management views.

Monitoring the CPU

We also recommend that database administrators monitor the following counters to understand the utilization of the host and virtual server CPU resources.

These three counters should provide you with enough information to determine if you have CPU bottlenecks. You should monitor these counters at both the host layer and the virtual server layer.

As with all performance monitoring, you should monitor on a continuous basis and then report less frequently—either daily or hourly. This gives you a more accurate picture of your performance.

System: Context Switching(below 1,000 per processor).

A high rate of context switching indicates resource queuing. In environments that have high rates of context switching, you should be careful to limit the applications and services that are placed on the boxes that are displaying the high context switch rates. The average value for this counter should remain below 1,000 per processor. Higher rates indicate that there may be CPU pressure, but this value should not be used as a single indicator of CPU pressure.

To use SQL Server dynamic management views instead of Performance Monitor for this counter, run the following query.

 

--Will work against databases in 80 compatibility mode
SELECT 'Context Switching by Scheduler'
SELECT cpu_id --ID of CPU if affinity mask in use (255 otherwise)
,is_online --Whether being used by SQL Server
,context_switches_count
,current_tasks_count
,current_workers_count
,active_workers_count
,pending_disk_io_count
,* 
FROM Sys.dm_os_schedulers

Processor(_Total): Privileged Time(Below 10 percent).

This counter measures the percentage of elapsed time that the process threads spent executing code in privileged mode. Average values above 10 percent indicate possible CPU pressure.

You should capture this counter for each individual processor.

Note that Privileged Time is a server-wide counter and therefore cannot be obtained through SQL Server 2005 dynamic management views.

Processor(_Total): Processor Time(below 80 percent).

This counter measures the percentage of elapsed time that all process threads used the processor to execute instructions. Average values above 80 percent indicate possible CPU pressure.

You should capture this counter for each individual processor.

Note that Processor Time is a server-wide counter and therefore cannot be obtained through SQL Server 2005 dynamic management views.

To Be Continued

We will continue to talk about performance baseline and tracking memory usage tomorrow. Sign up for our RSS feed so you know when the blog post is published.

Creating a Performance Baseline - Part 2

This is a continuation of yesterday's post. Today's topic is how to get a performance baseline for SQL Server's memory usage.

Why Do You Need a Memory Usage Performance Baseline?

We are going to show you how to monitor memory usage. Without a baseline, you won't know if SQL Server is using more or less memory than it should to run at full throttle.

Monitoring Memory

Database platforms are designed to consume as much memory as you will allow them to consume. This means that it is often critical to monitor memory use when you deal with SQL Server. Luckily, the SQL Server development team has included multiple methods to monitor memory for an instance of SQL Server.

We recommend that you watch the following SQL Server and memory metrics to understand the utilization of the virtual server memory resources:

· SQL Server: Buffer Manager Page Life Expectancy

· Memory: Pages/sec

· SQL Server: Buffer Manager: Free Pages

· Memory: Available Mbytes

· Memory: Free System Page Table Entries

· SQL Server: Memory Manager Memory Grants Pending

· Paging File(_Total): % Usage

You should monitor these counters at the virtual server layer.

Important: As with all performance monitoring, you will need to monitor on a continuous basis, but you should record your measurements in small time blocks, such as daily or hourly. This approach will prevent nonpeak hours from watering down the peak-hour readings and giving you a false view of performance.

SQL Server: Buffer Manager Page Life Expectancy.

Page life expectancy is the number of seconds a page will stay in the buffer pool without references. Values below 300 indicate possible memory pressure on the server.

In SQL Server 2005 and SQL Server 2008, the sys.dm_os_performance_counters dynamic management view returns the current value for the page life expectancy.

-- Page Life Expectancy
-- Will work against databases in 80 compatibility mode
SELECT *
FROM sys.dm_os_performance_counters
WHERE counter_name = 'Page life expectancy'

Memory: Pages/sec.

The Pages/sec counter shows the rate at which pages are read from or written to disk to resolve hard page faults. This counter is a primary indicator of the kinds of faults that cause system-wide delays. It is the sum of Memory\Pages Input/sec and Memory\Pages Output/sec. It is counted in numbers of pages, so it can be compared to other counts of pages, such as Memory\Page Faults/sec, without conversion. It includes pages that are retrieved to satisfy faults in the file system cache (usually requested by applications) and noncached mapped memory files.

A high value here (greater than 20) means that hard page faults (in which the operating system goes to the disk to resolve memory) are costing disk I/O and CPU resources. To resolve this problem, add more RAM, or remove other applications from the database server. Alternatively, limit the amount of memory that is available to SQL Server. Note that some paging will usually be present because of the way that the operating system works.

An average value of around 5 should be normal.

Pages/sec is a server-wide counter, so you can't obtain it through SQL Server 2005 dynamic management views.

SQL Server: Buffer Manager: Free Pages.

The Free Pages counter shows the total number of free pages on all free lists. Minimum values below 640 indicate memory pressure.

In SQL Server 2005 and SQL Server 2008, the sys.dm_os_performance_counters dynamic management view returns the current value for Free Pages.

-- Free Pages
-- Will work against databases in 80 compatibility mode
SELECT *
FROM sys.dm_os_performance_counters
WHERE counter_name = 'Free pages'
AND [object_name] LIKE '%BUFFER MANAGER%'

Memory: Available Mbytes.

The Available Mbytes counter shows the amount of memory that is available to processes that are running on the computer, in megabytes rather than in bytes, as reported by Memory\Available Bytes. This value should remain above 128. If the value falls below 128, memory pressure may be a problem if the system is paging which can be obtained from the performance counter Paging File(_Total): %Usage.

Available Mbytes is a server-wide counter, so you can't obtain it through SQL Server 2005 dynamic management views.

Memory: Free System Page Table Entries.

The Free System Page Table Entries counter shows the number of page table entries that are not currently in use by the system. This counter indicates memory pressure if it falls below 3,000. Typically, for systems that are not using the /3GB switch, this counter should be between 80,000 and 140,000. For systems that are using the /3GB switch, this counter should be about 15,000.

Free System Page Table Entries is a server-wide counter, so you can't obtain it through SQL Server 2005 dynamic management views.

SQL Server: Memory Manager Memory Grants Pending.

The Memory Grants Pending counter shows the current number of processes that are waiting for a workspace memory grant. This value should remain around 0.

In SQL Server 2005 and SQL Server 2008, the sys.dm_os_performance_counters dynamic management view returns the current value for Memory Grants Pending.

-- Memory Grants Pending
-- Will work against databases in 80 compatability mode
select * from sys.dm_os_performance_counters
WHERE counter_name like 'Memory Grants Pending%'

Paging File(_Total): % Usage.

The Paging File(_Total) counter shows the amount of the page file instance that is in use. This value should be below 70 percent; values over 70 percent indicate memory pressure. The use of the paging file with SQL Server indicates that the Lock pages in memory policy setting has not been enabled for the SQL Server service account.

Paging file usage is a server-wide counter, so you can't obtain it through SQL Server 2005 dynamic management views.

Metrics Reference Baseline

So where is your baseline? Watch these metrics over a period of time, and see where your deployment hangs out most often. You want the values to be in the target measurement range that we show in the following table. If they are not, it's a good indication that you need to tweak something to squeeze the best performance from Workforce Central on SQL Server.

Metric

Target measurement

SQL Server: Buffer Manager Page Life Expectancy

Greater than 300

Memory: Pages/sec

Less than 20

SQL Server: Buffer Manager: Free Pages

Greater than 640

Memory: Available Mbytes

Greater than 128

Memory: Free System Page Table Entries

Greater than 3,000

SQL Server: Memory Manager Memory Grants Pending

0

Paging File(_Total): % Usage

Less than 70 percent

from http://blogs.msdn.com/b/kronos/archive/2010/03/23/creating-a-performance-baseline-part-1.asp




    本文转自 Fanr_Zh 博客园博客,原文链接:http://www.cnblogs.com/Amaranthus/archive/2011/04/09/2010390.html,如需转载请自行联系原作者


相关实践学习
使用SQL语句管理索引
本次实验主要介绍如何在RDS-SQLServer数据库中,使用SQL语句管理索引。
SQL Server on Linux入门教程
SQL Server数据库一直只提供Windows下的版本。2016年微软宣布推出可运行在Linux系统下的SQL Server数据库,该版本目前还是早期预览版本。本课程主要介绍SQLServer On Linux的基本知识。 相关的阿里云产品:云数据库RDS SQL Server版 RDS SQL Server不仅拥有高可用架构和任意时间点的数据恢复功能,强力支撑各种企业应用,同时也包含了微软的License费用,减少额外支出。 了解产品详情: https://www.aliyun.com/product/rds/sqlserver
相关文章
|
13天前
|
SQL 人工智能 算法
【SQL server】玩转SQL server数据库:第二章 关系数据库
【SQL server】玩转SQL server数据库:第二章 关系数据库
52 10
|
23天前
|
SQL
启动mysq异常The server quit without updating PID file [FAILED]sql/data/***.pi根本解决方案
启动mysq异常The server quit without updating PID file [FAILED]sql/data/***.pi根本解决方案
17 0
|
13天前
|
SQL 算法 数据库
【SQL server】玩转SQL server数据库:第三章 关系数据库标准语言SQL(二)数据查询
【SQL server】玩转SQL server数据库:第三章 关系数据库标准语言SQL(二)数据查询
78 6
|
1天前
|
SQL 关系型数据库 MySQL
:“You have an error in your SQL syntax; check the manual that corresponds to your MySQL server versi
:“You have an error in your SQL syntax; check the manual that corresponds to your MySQL server versi
6 0
|
8天前
|
SQL 安全 网络安全
IDEA DataGrip连接sqlserver 提示驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接的解决方法
IDEA DataGrip连接sqlserver 提示驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接的解决方法
19 0
|
13天前
|
SQL 存储 数据挖掘
数据库数据恢复—RAID5上层Sql Server数据库数据恢复案例
服务器数据恢复环境: 一台安装windows server操作系统的服务器。一组由8块硬盘组建的RAID5,划分LUN供这台服务器使用。 在windows服务器内装有SqlServer数据库。存储空间LUN划分了两个逻辑分区。 服务器故障&初检: 由于未知原因,Sql Server数据库文件丢失,丢失数据涉及到3个库,表的数量有3000左右。数据库文件丢失原因还没有查清楚,也不能确定数据存储位置。 数据库文件丢失后服务器仍处于开机状态,所幸没有大量数据写入。 将raid5中所有磁盘编号后取出,经过硬件工程师检测,没有发现明显的硬件故障。以只读方式将所有磁盘进行扇区级的全盘镜像,镜像完成后将所
数据库数据恢复—RAID5上层Sql Server数据库数据恢复案例
|
17天前
|
SQL 数据安全/隐私保护
SQL Server 2016安装教程
SQL Server 2016安装教程
19 1
|
17天前
|
SQL 安全 Java
SQL server 2017安装教程
SQL server 2017安装教程
15 1
|
30天前
|
SQL 存储 Python
Microsoft SQL Server 编写汉字转拼音函数
Microsoft SQL Server 编写汉字转拼音函数
|
1月前
|
SQL 存储 数据库
数据安全无忧,SQL Server 2014数据库定时备份解密
数据安全无忧,SQL Server 2014数据库定时备份解密