Resource Governor is a feature that you can use to manage SQL Server workload and system resource consumption. Resource Governor enables you to specify limits on the amount of CPU, physical I/O, and memory that incoming application requests can use.
/*step1 Enable SQL Server Resource Governor
ALTER RESOURCE GOVERNOR RECONFIGURE;
GO
/*step2 Create resource pool and set limits.
CREATE RESOURCE POOL PoolAdmin WITH (MAX_CPU_PERCENT = 50);
/*step3 Create Resource Governor Workload Group in that pool
CREATE WORKLOAD GROUP [GroupAdmin]
CREATE WORKLOAD GROUP [Quries]
GO
/*step4 Direct relevant connections or hosts to those workload groups by using classifier function
USE [master]
GO
CREATE FUNCTION [dbo].[RG_Classifier]()
RETURNS SYSNAME
WITH SCHEMABINDING
AS
BEGIN
DECLARE @grp_name sysname
IF (SUSER_NAME() = 'sa')
SET @grp_name = 'GroupAdmin'
IF (HOST_NAME() = 'hostclient')
SET @grp_name = 'Quries'
ELSE
SET @grp_name = 'default'
RETURN @grp_name
END;
GO
/*step5 Testing i.e. run the quries from host and check result
USE master;
SELECT * FROM sys.resource_governor_configuratin;
SELECT * FROM sys.resource_governor_resource_pools;
SELECT * FROM sys.resource_governor_workload_groups;
SELECT object_schema_name(classifier_function_id) AS [schema_name],
object_name(classifier_function_id) AS [function_name]
FROM sys.dm_resource_governor_configuration;
--Find out what sessions are in each group by using the following query.
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))
FROM sys.dm_exec_sessions AS s
INNER JOIN sys.dm_resource_governor_workload_groups AS g
ON g.group_id = s.group_id
ORDER BY g.name;
GO
GO
source-
https://docs.microsoft.com/en-us/sql/relational-databases/resource-governor/create-and-test-a-classifier-user-defined-function?view=sql-server-ver15