You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/relational-databases/resource-governor/create-and-test-a-classifier-user-defined-function.md
+49-45Lines changed: 49 additions & 45 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: "Create and Test a Classifier User-Defined Function | Microsoft Docs"
3
3
ms.custom: ""
4
-
ms.date: "03/16/2017"
4
+
ms.date: "07/11/2017"
5
5
ms.prod: "sql-server-2016"
6
6
ms.reviewer: ""
7
7
ms.suite: ""
@@ -45,22 +45,22 @@ manager: "jhubbard"
45
45
```
46
46
--- Create a resource pool for production processing
47
47
--- and set limits.
48
-
USE master
48
+
USE master;
49
49
GO
50
50
CREATE RESOURCE POOL pProductionProcessing
51
51
WITH
52
52
(
53
53
MAX_CPU_PERCENT = 100,
54
54
MIN_CPU_PERCENT = 50
55
-
)
55
+
);
56
56
GO
57
57
--- Create a workload group for production processing
58
58
--- and configure the relative importance.
59
59
CREATE WORKLOAD GROUP gProductionProcessing
60
60
WITH
61
61
(
62
62
IMPORTANCE = MEDIUM
63
-
)
63
+
);
64
64
--- Assign the workload group to the production processing
65
65
--- resource pool.
66
66
USING pProductionProcessing
@@ -73,7 +73,7 @@ manager: "jhubbard"
73
73
(
74
74
MAX_CPU_PERCENT = 50,
75
75
MIN_CPU_PERCENT = 0
76
-
)
76
+
);
77
77
GO
78
78
--- Create a workload group for off-hours processing
79
79
--- and configure the relative importance.
@@ -84,32 +84,32 @@ manager: "jhubbard"
84
84
)
85
85
--- Assign the workload group to the off-hours processing
86
86
--- resource pool.
87
-
USING pOffHoursProcessing
87
+
USING pOffHoursProcessing;
88
88
GO
89
89
```
90
90
91
91
2. Update the in-memory configuration.
92
92
93
93
```
94
-
ALTER RESOURCE GOVERNOR RECONFIGURE
94
+
ALTER RESOURCE GOVERNOR RECONFIGURE;
95
95
GO
96
96
```
97
97
98
98
3. Create a table and define the start and end times for the production processing time range.
99
99
100
100
```
101
-
USE master
101
+
USE master;
102
102
GO
103
103
CREATE TABLE tblClassificationTimeTable
104
104
(
105
105
strGroupName sysname not null,
106
106
tStartTime time not null,
107
107
tEndTime time not null
108
-
)
108
+
);
109
109
GO
110
110
--- Add time values that the classifier will use to
111
111
--- determine the workload group for a session.
112
-
INSERT into tblClassificationTimeTable VALUES('gProductionProcessing', '6:35 AM', '6:15 PM')
112
+
INSERT into tblClassificationTimeTable VALUES('gProductionProcessing', '6:35 AM', '6:15 PM');
113
113
go
114
114
```
115
115
@@ -124,7 +124,9 @@ manager: "jhubbard"
124
124
WITH SCHEMABINDING
125
125
AS
126
126
BEGIN
127
-
/* We recommend running the classifier function code under snapshot isolation level OR using NOLOCK hint to avoid blocking on lookup table. In this example, we are using NOLOCK hint. */
127
+
/* We recommend running the classifier function code under
128
+
snapshot isolation level OR using NOLOCK hint to avoid blocking on
129
+
lookup table. In this example, we are using NOLOCK hint. */
128
130
DECLARE @strGroup sysname
129
131
DECLARE @loginTime time
130
132
SET @loginTime = CONVERT(time,GETDATE())
@@ -138,15 +140,15 @@ manager: "jhubbard"
138
140
--- Use the default workload group if there is no match
139
141
--- on the lookup.
140
142
RETURN N'gOffHoursProcessing'
141
-
END
143
+
END;
142
144
GO
143
145
```
144
146
145
147
5. Register the classifier function and update the in-memory configuration.
146
148
147
149
```
148
-
ALTER RESOURCE GOVERNOR with (CLASSIFIER_FUNCTION = dbo.fnTimeClassifier)
149
-
ALTER RESOURCE GOVERNOR RECONFIGURE
150
+
ALTER RESOURCE GOVERNOR with (CLASSIFIER_FUNCTION = dbo.fnTimeClassifier);
151
+
ALTER RESOURCE GOVERNOR RECONFIGURE;
150
152
GO
151
153
```
152
154
@@ -155,76 +157,78 @@ manager: "jhubbard"
155
157
1. Obtain the resource pool and workload group configuration by using the following query.
156
158
157
159
```
158
-
USE master
159
-
SELECT * FROM sys.resource_governor_resource_pools
160
-
SELECT * FROM sys.resource_governor_workload_groups
160
+
USE master;
161
+
SELECT * FROM sys.resource_governor_resource_pools;
162
+
SELECT * FROM sys.resource_governor_workload_groups;
161
163
GO
162
164
```
163
165
164
166
2. Verify that the classifier function exists and is enabled by using the following queries.
165
167
166
168
```
167
169
--- Get the classifier function Id and state (enabled).
168
-
SELECT * FROM sys.resource_governor_configuration
170
+
SELECT * FROM sys.resource_governor_configuration;
169
171
GO
170
172
--- Get the classifer function name and the name of the schema
171
173
--- that it is bound to.
172
174
SELECT
173
175
object_schema_name(classifier_function_id) AS [schema_name],
174
176
object_name(classifier_function_id) AS [function_name]
175
-
FROM sys.dm_resource_governor_configuration
176
-
177
+
FROM sys.dm_resource_governor_configuration;
177
178
```
178
179
179
180
3. Obtain the current runtime data for the resource pools and workload groups by using the following query.
180
181
181
182
```
182
-
SELECT * FROM sys.dm_resource_governor_resource_pools
183
-
SELECT * FROM sys.dm_resource_governor_workload_groups
183
+
SELECT * FROM sys.dm_resource_governor_resource_pools;
184
+
SELECT * FROM sys.dm_resource_governor_workload_groups;
184
185
GO
185
186
```
186
187
187
188
4. Find out what sessions are in each group by using the following query.
188
189
189
190
```
190
-
SELECT s.group_id, CAST(g.name as nvarchar(20)), s.session_id, s.login_time, CAST(s.host_name as nvarchar(20)), CAST(s.program_name AS nvarchar(20))
191
-
FROM sys.dm_exec_sessions s
192
-
INNER JOIN sys.dm_resource_governor_workload_groups g
193
-
ON g.group_id = s.group_id
194
-
ORDER BY g.name
191
+
SELECT s.group_id, CAST(g.name as nvarchar(20)), s.session_id, s.login_time,
192
+
CAST(s.host_name as nvarchar(20)), CAST(s.program_name AS nvarchar(20))
193
+
FROM sys.dm_exec_sessions AS s
194
+
INNER JOIN sys.dm_resource_governor_workload_groups AS g
195
+
ON g.group_id = s.group_id
196
+
ORDER BY g.name;
195
197
GO
196
198
```
197
199
198
200
5. Find out which requests are in each group by using the following query.
0 commit comments