SQL Server 创建性能基线

本文涉及的产品
云数据库 RDS SQL Server,基础系列 2核4GB
RDS SQL Server Serverless,2-4RCU 50GB 3个月
推荐场景:
简介: Creating a Performance Baseline - Part 1 You'll often hear that you should monitor the performance of SQL Server.

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.aspx
相关实践学习
使用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
目录
相关文章
|
2月前
|
关系型数据库 MySQL 网络安全
5-10Can't connect to MySQL server on 'sh-cynosl-grp-fcs50xoa.sql.tencentcdb.com' (110)")
5-10Can't connect to MySQL server on 'sh-cynosl-grp-fcs50xoa.sql.tencentcdb.com' (110)")
|
4月前
|
SQL 存储 监控
SQL Server的并行实施如何优化?
【7月更文挑战第23天】SQL Server的并行实施如何优化?
115 13
|
4月前
|
SQL
解锁 SQL Server 2022的时间序列数据功能
【7月更文挑战第14天】要解锁SQL Server 2022的时间序列数据功能,可使用`generate_series`函数生成整数序列,例如:`SELECT value FROM generate_series(1, 10)。此外,`date_bucket`函数能按指定间隔(如周)对日期时间值分组,这些工具结合窗口函数和其他时间日期函数,能高效处理和分析时间序列数据。更多信息请参考官方文档和技术资料。
|
4月前
|
SQL 存储 网络安全
关系数据库SQLserver 安装 SQL Server
【7月更文挑战第26天】
61 6
|
4月前
|
存储 SQL C++
对比 SQL Server中的VARCHAR(max) 与VARCHAR(n) 数据类型
【7月更文挑战7天】SQL Server 中的 VARCHAR(max) vs VARCHAR(n): - VARCHAR(n) 存储最多 n 个字符(1-8000),适合短文本。 - VARCHAR(max) 可存储约 21 亿个字符,适合大量文本。 - VARCHAR(n) 在处理小数据时性能更好,空间固定。 - VARCHAR(max) 对于大文本更合适,但可能影响性能。 - 选择取决于数据长度预期和业务需求。
382 1
|
3月前
|
SQL 安全 Java
驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。错误:“The server selected protocol version TLS10 is not accepted by client
驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。错误:“The server selected protocol version TLS10 is not accepted by client
480 0
|
4月前
|
SQL Oracle 关系型数据库
MySQL、SQL Server和Oracle数据库安装部署教程
数据库的安装部署教程因不同的数据库管理系统(DBMS)而异,以下将以MySQL、SQL Server和Oracle为例,分别概述其安装部署的基本步骤。请注意,由于软件版本和操作系统的不同,具体步骤可能会有所变化。
309 3
|
4月前
|
SQL 存储 安全
数据库数据恢复—SQL Server数据库出现逻辑错误的数据恢复案例
SQL Server数据库数据恢复环境: 某品牌服务器存储中有两组raid5磁盘阵列。操作系统层面跑着SQL Server数据库,SQL Server数据库存放在D盘分区中。 SQL Server数据库故障: 存放SQL Server数据库的D盘分区容量不足,管理员在E盘中生成了一个.ndf的文件并且将数据库路径指向E盘继续使用。数据库继续运行一段时间后出现故障并报错,连接失效,SqlServer数据库无法附加查询。管理员多次尝试恢复数据库数据但是没有成功。