programming4us
programming4us
DATABASE

SQL Server 2008: Managing Resources with the Resource Governor (part 3) - Classifier Function

2/22/2011 9:16:48 AM

16.8.3. Classifier Function

The classifier function is a T-SQL function that is executed for each login, which allows you to write logic to route incoming requests to the appropriate workload group. You must create the classifier function in the master database, and the Resource Governor can only use one classifier function at any given time. You can, however, create multiple classifier functions and dynamically change which function the Resource Governor uses. You can use the following functions to help you create your classifier function:

  • HOST_NAME()

  • APP_NAME()

  • SUSER_NAME()

  • SUSER_SNAME()

  • IS_SRVROLEMEMBER()

  • IS_MEMBER()

  • LOGINPROPERTY(suser_name(),'DefaultDatabase')

  • LOGINPROPERTY(suser_name(),'DefaultLanguage')

  • ORIGINAL_DB_NAME()

  • CONNECTIONPROPERTY(<PropertyName>)

You can also create a lookup table to help you with your classifier function. For example, you may want to send certain processes to a different workload group, depending on a schedule you have defined in your lookup table. However, you need to keep in mind that SQL Server will execute the classifier function for each login, so it should be as efficient as possible in order to prevent performance issues. A good thing to keep in mind is that the dedicated administrator connection will never be classified, so you can always log in using this connection to fix any issues you may encounter.

The workload groups used in the classifier function are case sensitive. If you do not use the correct case when referencing the workload groups, the requests will be routed to the default workload group.


Let's create a classifier function that will route the incoming requests to the workload groups shown in Figure 16-15 by running the script in Listing 3.

Example 3. Code to Create and Enable a Classifier Function
USE master
GO

CREATE FUNCTION RG_Classifier_V1 ()
RETURNS sysname
WITH SCHEMABINDING
AS
BEGIN

DECLARE @GroupName sysname

IF (IS_MEMBER('KEN-PC\TestingGroup') = 1)
SET @GroupName = 'TestingGroup'

ELSE IF (APP_NAME() LIKE '%REPORT SERVER%')
SET @GroupName = 'ReportingGroup'

ELSE IF (SUSER_NAME() = 'BackupUser')
SET @GroupName = 'BackupGroup'

ELSE
SET @GroupName = 'default'

RETURN @GroupName

END
GO

--Assign the function to the Resource Governor and reconfigure
ALTER RESOURCE GOVERNOR WITH (CLASSIFIER_FUNCTION = dbo.RG_Classifier_V1)
GO
ALTER RESOURCE GOVERNOR RECONFIGURE
GO

You can see the completed configuration (shown in Figure 3) by right-clicking on Resource Governor in SQL Server Management Studio and selecting Properties from the context menu.

Figure 3. Resource Governor properties

In order to remove a classifier function from the Resource Governor, you can run the ALTER RESOURCE GOVERNOR statement and specify the new classifier name, or NULL if you want to remove all classifier functions and send all requests to the default workload group. The statement in Listing 4 will remove all classifier functions from the Resource Governor.

Example 4. Code to Remove All Classifier Functions from the Resource Governor
ALTER RESOURCE GOVERNOR WITH (CLASSIFIER_FUNCTION = NULL);
GO
ALTER RESOURCE GOVERNOR RECONFIGURE;

Other  
 
video
 
Video tutorials
- How To Install Windows 8

- How To Install Windows Server 2012

- How To Install Windows Server 2012 On VirtualBox

- How To Disable Windows 8 Metro UI

- How To Install Windows Store Apps From Windows 8 Classic Desktop

- How To Disable Windows Update in Windows 8

- How To Disable Windows 8 Metro UI

- How To Add Widgets To Windows 8 Lock Screen

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010
programming4us programming4us
programming4us
 
 
programming4us