Resource Governor is a new technology in SQL Server 2008 that enables you to manage SQL Server workload and resources by specifying limits on resource consumption by incoming requests. this is the first time Microsoft enables you to have any control of resource usage by processes,this is for me one of the most important features of SQL server 2008 , this is a “killer feature” or a reason to move to SQL Server 2008 tomorrow morning!(for me at least :-)) ,why is that so important? in many real world scenarios you have different workloads on your server ,meaning many different applications and users are running different type of queries,this queries can have different scope (OLTP,DW) ,so actually as many of you probably encountered over the years ,one query can “choke” your server ,this sometimes referred to as a “Runaway” Query,before SQL Server 2008 you could not control resource consumption in any form ,so Resource Governor In SQL 2008 is a big big change ,let’s see the concept’s of Resource Governor (most of this is from BOL) :
The following three concepts are fundamental to understanding and using Resource Governor:
- Resource pools. Two resource pools (internal and default) are created when SQL Server 2008 is installed. Resource Governor also supports user-defined resource pools.
- Workload groups. Two workload groups (internal and default) are created and mapped to their corresponding resource pools when SQL Server 2008 is installed. Resource Governor also supports user-defined workload groups.
- Classification. There are internal rules that classify incoming requests and route them to a workload group. Resource Governor also supports a classifier user-defined function for implementing classification rules.
so if a look at a conceptual drawing it would look like this :
we can assign different workloads to different resource pools ,and control resources (cpu,memory) . the relationships between sessions ,pools,workload groups is explained in the following diagram :
assigning sessions to workload groups is done by the classifier function that you create yourself ,let’s see a sample of a classifier function :
CREATE FUNCTION fnTimeClassifier()
RETURNS sysname
WITH SCHEMABINDING
AS
BEGIN
DECLARE @strGroup sysname
DECLARE @loginTime time
SET @loginTime = CONVERT(time,GETDATE())
SELECT TOP 1 @strGroup = strGroupName
FROM dbo.tblClassificationTimeTable
WHERE tStartTime <= @loginTime and tEndTime >= @loginTime
IF(@strGroup is not null)
BEGIN
RETURN @strGroup
END
— Use the default workload group if there is no match
— on the lookup.
RETURN N'gOffHoursProcessing'
END
GO
this function (2008 BOL) ,is using a time table to return the workload group that the user should be assigned too ,based on the current time.
assigning and changing the resource governor is done online ,by the following statements :
ALTER RESOURCE GOVERNOR with (CLASSIFIER_FUNCTION = dbo.fnTimeClassifier) ALTER RESOURCE GOVERNOR RECONFIGURE GO
controlling the resources (CPU,MEMORY) is also done online ,without requiring any stop start of any service ,for instance :
— adjust PoolMarketing to not consume more than 10% of CPU
ALTER RESOURCE POOL PoolMarketing
WITH (MAX_CPU_PERCENT = 10)