Reporting Sessions OLTP Sessions Classification Classifier Function Internal Group Internal Pool Group Default Pool Pool 1 Group 2 Pool 2 Query Optimizer FIGURE 40.1 Overview of the Reso
Trang 1Reporting
Sessions
OLTP Sessions
Classification (Classifier Function)
Internal
Group
Internal
Pool
Group
Default Pool Pool 1
Group 2
Pool 2
Query Optimizer
FIGURE 40.1 Overview of the Resource Governor
NOTE
Resource Governor is available only in the Enterprise, Datacenter, and Developer
Editions of SQL Server 2008 and SQL Server 2008 R2
Overview of Resource Governor
Resource Governor works by controlling the allocation of resources according to
work-loads When a connection request is submitted to the Database Engine, the request is
clas-sified based on a classification function The classification function is a scalar function
that you define via T-SQL The classification function evaluates information about the
connection (for example, login ID, application name, hostname, server role) to determine
how it should be classified After the connection request is classified, it is routed to a
workload group defined for that classification (or if the connection cannot be classified, it
is routed to the default workload group) Each workload group is associated with a
resource pool A resource pool represents the physical resources of SQL Server (currently in
SQL Server 2008, the only physical resources available for configuration are CPU and
memory) and specifies the maximum amount of CPU and/or memory resources that are to
be allocated to a specific type of workload When a connection is classified and put into
the correct workload group, the connection is allocated the CPU and memory resources
assigned to it, and then the query is passed on to the query optimizer for execution This
process is illustrated in Figure 40.1
Trang 2Resource Governor is designed to address the following types of resource issues, which are
commonly found in a database environment:
Runaway queries—These resource-intensive queries can take up most or all of the
server resources
Unpredictable workload execution—This situation occurs when you have
concurrent applications on the same server that are not isolated from each other,
and the resulting resource contention causes unpredictable performance
Workload prioritization—You might want to ensure that a critical workload is
given priority to the system resources so it can process faster than other workloads
or is guaranteed to complete if there is resource contention
In addition to enabling you to classify incoming connections and route their workloads to
a specific group, Resource Governor also enables you to do the following:
Monitor resource usage for each workload in a group
Pool resources and set pool-specific limits on CPU usage and memory allocation,
which can prevent or minimize the probability of runaway queries
Associate grouped workloads with a specific pool of resources
Identify and set priorities for workloads
The current release of Resource Governor has the following limitations:
Resource allocation is only for CPU and memory usage There is no support for
managing network and disk I/O resource utilization
Resource Governor manages only resource consumption of the Database Engine You
cannot use Resource Governor to manage workloads within SSAS, SSIS, or SSRS
In the following sections, you learn how to set up and configure Resource Governor for
use, how Resource Governor works under the hood, and how you can use Resource
Governor to better prioritize and manage a SQL Server’s workload
Resource Governor Components
Resource Governor consists of three main components: classification, workload groups,
and resource pools Understanding these three components and how they interact is
important to understanding and using Resource Governor
Classification
Classification is the process of evaluating incoming user connections and assigning them
to a workload group Classification is performed by logic contained in a user-defined
func-tion The function returns the workload group name, which Resource Governor uses to
route the sessions into the appropriate workload groups
Trang 3When Resource Governor is configured, the login process for a session consists of the
following steps:
1 Login authentication
2 LOGON trigger execution
3 Classification
Workload Groups
Workload groups are the containers for similar connections, which are grouped together as
similar according to the classification criteria applied to each connection A workload
group also provides the mechanism for aggregate monitoring of resource consumption
Resource Governor has two predefined workload groups: the internal group and default
group The internal workload group is used solely by internal Database Engine processes
You cannot change the classification criteria for the internal group, and you also cannot
classify any user requests for assignment to the internal group You can, however, monitor
the internal group
Connection requests are automatically classified into the default group when the
follow-ing conditions exist:
There are no criteria to classify a request
There is an attempt to classify the request into a nonexistent group
There is a general classification failure
Resource governor supports a total of 20 workload groups Because two of them are
reserved for the internal and default workload groups, a total of 18 user-defined workload
groups can be defined
Resource Pools
A resource pool, or pool, represents the allocation of physical resources of the SQL Server A
resource pool has two parts:
The first part specifies the minimum resource reservation This part of the resource
pool does not overlap with other pools
The other part specifies the maximum possible resource reservation for the pool The
resource allocation is shared with other pools
In SQL Server 2008 and SQL Server 2008 R2, the pool resources are set by specifying a MIN
orMAXallocation for CPU and a MINorMAXallocation for memory The MINsetting specifies
the minimum guaranteed resource availability of the pool The MAXsetting sets the
maximum size of the pool for each of the resources
Because there cannot be any overlap in the minimum resource reservation, the sum of the
MINvalues across all pools cannot exceed 100% of the total server resources The ensures
that each pool is guaranteed the specified resource allocation
Trang 4TheMAXvalue can be set anywhere in the range between the MINvalue and 100%
inclu-sive The MAXsetting represents the maximum amount of resources a session can consume,
as long as the resources are available and not in use by another pool that is configured
with a nonzero MIN value When a pool has a nonzero MINpercentage defined, the
effec-tiveMAXvalue of other pools is readjusted down, as necessary, to the existing MAXvalue
minus the sum total of the MINvalues of other pools
For example, consider you have two user-defined pools One pool, Pool1, is defined with a
MINsetting of 20% and a MAXsetting of 100% The other pool, Pool2, is defined with a MIN
setting of 50% and a MAXsetting of 70% The resulting effective MAX setting for Pool1 is
50% (100% minus the MIN50% of Pool2) The effective MAXsetting of Pool2, however,
remains at 70% rather than 80% because 70% is the configured MAXvalue of Pool2
The shared part of the pool (the amount between the MINand effective MAXvalues) is used
to determine the amount of resources that can be consumed by the pool if the resources
are available and not being consumed by another pool When resources are consumed by
a pool, they are assigned to the specified pool and are not shared until processing
completes in that pool
To illustrate this further, consider a scenario in which there are three user-defined
resource pools:
PoolA is defined with a MIN %of 10 and MAX %of 100
PoolB is defined with a MIN %of 35 and a MAX %of 90
PoolC is defined with a MIN %of 30 and a MAX %of 80
The effective MAXof PoolA would be calculated as follows:
MAX %of PoolA 100
minusMIN %of PoolB 35
minusMIN %of PoolC 30
equalsEFF MAXof PoolA 35
The total Shared %of resources of PoolA would then be calculated as follows:
EffectiveMAX% of PoolA 35
minusMIN %of PoolA 10
equalsShared %of PoolA 25
Table 40.1 illustrates the calculated effective MAXandShared %values for all pools in this
configuration
Trang 5To coincide with the predefined workload groups, Resource Governor also has two
prede-fined resource pools: the internal pool and default pool
The internal pool represents the resources consumed by the internal processes of the
Database Engine This pool always contains only the internal group, and the pool is not
alterable in any way The Internal Pool has a fixed MIN %of 0 and a MAX %of 100, and
resource consumption by the internal pool is not restricted or reduced by any settings in
other pools In other words, the effective MAXof the Internal Pool is always 100% Any
workloads in the internal pool are considered critical for server function, and Resource
Governor allows the internal pool to consume 100% of available resources if necessary,
even if it means the violation of the resource requirements of the other pools
The default pool is the first predefined user pool Prior to any configuration, the default pool
contains only the default group The default pool cannot be created or dropped, but it can be
altered The default pool can contain user-defined groups in addition to the default group
Now that you have an understanding of the Resource Governor components, let’s put
them into use by enabling and setting up some resource groups
Configuring Resource Governor
To begin using Resource Governor for managing the resources of your workloads, follow
these steps:
1 Enable Resource Governor
2 Create your user-defined resource pools
3 Define your workload groups and assign them to pools
4 Create the classifier function
5 Register the classifier function with the Resource Governor
NOTE
Resource Governor can be set up and managed using either SQL Server Management
Studio (SSMS) or via T-SQL commands In the following sections, we first show you
how to perform the tasks in SSMS and how the same actions can be implemented
using T-SQL
TABLE 40-1 EffectiveMAX and Shared % Values for Multiple Pools
ResourcePool MIN % MAX % EffectiveMAX % Shared %
Trang 6FIGURE 40.2 Enabling Resource Governor in SSMS
Enabling Resource Governor
Before you can begin creating your resource pools, you need to enable the Resource
Governor first To enable Resource Governor in SSMS, in Object Explorer, expand the
Managementnode, right-click on the Resource Governornode, and select Enable (see
Figure 40.2)
Alternatively, you can also enable Resource Governor by using the ALTER RESOURCE
GOVERNORcommand in T-SQL:
ALTER RESOURCE GOVERNOR RECONFIGURE
When Resource Governor is not enabled, the RECONFIGUREoption enables Resource
Governor Enabling Resource Governor has the following results:
The classifier function, if defined, is executed for new connections so that their
workload can be assigned to workload groups
The resource limits specified in the Resource Governor configuration are honored
and enforced
Any connections that existed before Resource Governor was enabled are now
affect-ed by any configuration changes made when Resource Governor was disablaffect-ed
When Resource Governor is already enabled, the RECONFIGUREoption must be executed to
apply any configuration changes made using the CREATE|ALTER|DROP WORKLOAD GROUPor
CREATE|ALTER|DROP RESOURCE POOLstatements
Trang 7To determine whether Resource Governor is currently enabled, you can run a SELECT
state-ment against the sys.resource_governor_configurationsystem catalog table to view the
is_enabledcolumn:
select is_enabled from sys.resource_governor_configuration
go
is_enabled
-1
To determine whether anyRESOURCE GOVERNORconfiguration changes are pending, you can
use thesys.dm_resource_governor_configurationdynamic management view (DMV):
select is_reconfiguration_pending
from sys.dm_resource_governor_configuration
go
is_reconfiguration_pending
-0
To disable Resource Governor, right-click on the Resource Governornode and select
Disable or execute the following command in T-SQL:
ALTER RESOURCE GOVERNOR DISABLE
Defining Resource Pools
When setting up a Resource Pool, you have to specify a name for the pool and set its
properties The properties available for a resource pool are
Name—The name used to refer to the resource pool
Minimum CPU %—The guaranteed average CPU bandwidth for all requests to the
resource pool when there is CPU contention
Maximum CPU %—The maximum average CPU bandwidth for all requests to the
resource pool when there is CPU contention
Min Memory %—The guaranteed minimum amount of memory reserved for the
resource pool that cannot be shared with other resource pools
Max Memory %—The total server memory that can be used by requests to the
resource pool
Creating a Resource Pool in SSMS
The following steps walk you through using SSMS to create a resource pool named
ReportPoolthat you’ll configure for handling report query workloads:
Trang 8FIGURE 40.3 Creating a resource pool in SSMS
1 In Object Explorer, expand the Managementnode for a SQL Server Instance and
expand the Resource Governornode
2 Right-click on Resource Pools and select New Resource Pool to open the Resource
Governor Properties page (see Figure 40.3)
3 In the Resource Pools grid, click the first column in the empty row This row is
labeled with an asterisk (*)
NOTE
If the Resource Pools grid does not have a row labeled with an asterisk, Resource
Governor has not been enabled yet You can enable Resource Governor without leaving
the Resource Governor Properties page by putting a check mark in the Enable
Resource Governor check box
4 Double-click the empty cell in the Namecolumn Type in the name that you want to
use for the resource pool For this example, use the name ReportPool
5 Set the CPU and Memory resource values In this example, leave the Min CPU %and
Min Memory %values at 0 and configure the Max CPU %andMax Memory %values at
20 and 30, respectively
6 To create the pool and exit the dialog, click OK
To verify that the new pool was created, you expand the Resource Poolsfolder under the
Resource Governornode and look for a node named ReportPool Alternatively, you can
Trang 9run a query against the sys.resource_governor_resource_poolsdynamic management
view, similar to the following, which also displays the resource pool configuration:
select name,
min_cpu_percent as MinCPU,
max_cpu_percent as MaxCPU,
min_memory_percent as ‘MinMEM%’ ,
max_memory_percent as ‘MaxMEM%’
from sys.resource_governor_resource_pools
go
name MinCPU MaxCPU MinMEM% MaxMEM%
- - -
-internal 0 100 0 100
default 0 100 0 100
ReportPool 0 20 0 30
Creating a Resource Pool in T-SQL
Now that you’ve set up the ReportPoolresource pool in SSMS, you are able to set up a
second resource pool, OLTPPool, using T-SQL The command to create a resource pool,
CREATE RESOURCE POOL, takes four arguments: MIN_CPU_PERCENT,MAX_CPU_PERCENT,
MIN_MEMORY_PERCENT, and MAX_MEMORY_PERCENT After creating the resource pool, you need
to run ALTER RESOURCE GOVERNOR RECONFIGUREto apply the new resource pool:
CREATE RESOURCE POOL OLTPPool
WITH
(min_cpu_percent=80,
max_cpu_percent=100,
min_memory_percent=75,
max_memory_percent=100)
GO
ALTER RESOURCE GOVERNOR RECONFIGURE;
GO
Now that you’ve defined the resource pools needed, the next step is to define your
work-load groups and associate them with a resource pool
Defining Workload Groups
After you define your resource pools, the next step is to create the workload groups and
associate them with the appropriate resource pools Multiple workgroups can be assigned
to that same pool, but a workgroup cannot be assigned to multiple resource pools
Trang 10Creating Workload Groups in SSMS
To create a workload group in SSMS, perform the following steps:
1 In Object Explorer, expand the Managementnode, right-click the Resource Governor
node, and then click Properties to bring up the Resource Governor Properties page
2 In the Resource Pools grid, click the row for the resource pool you want to create a
workload groupfor (in this example, the ReportPoolresource pool) This creates a
new empty row in the Workload Groups for Resource Pool grid for that pool
3 Double-click the empty cell in the Namecolumn for the empty workload group row
and type in the name you want to use for the workload group (for this example,
ReportWG1) and any other properties you want to specify (see Figure 40.4)
4 Click OK to exit the Properties page and create the workload group
The additional, optional properties available for workload groups let you set a finer level
of control over the execution of queries within a workload group The options available
are
Importance—Specifies the relative importance (LOW,MEDIUM, or HIGH) of the
work-load group within the resource pool If you define multiple workwork-load groups in a
FIGURE 40.4 Creating a Workload Group in SSMS