|
|||
|
The economic tough times are affecting everyone these days. Most, if not all, corporations are looking for ways to save money and get more value out of their existing infrastructure. One of the areas getting a lot of attention from IT managers is how they can consolidate servers to help minimize hardware and license costs.
With any consolidation effort you need to be concerned about how well merged application and/or database services will play together. One application can potentially steal valuable resources away from another, decreasing the performance of your critical applications. As you start to think about how your corporation might take advantage of consolidation for your SQL Server environment, you might want to look at SQL Server 2008. A new feature called Resource Governor can help you manage CPU and memory usage by throttling down resource-intensive processes.
What Problem Does Resource Governor Solve? Shortly after consolidating these two applications you start receiving complaints. The phone operators that take customer order are complaining about sporadic response time in the online order entry system. It isn't slow all the time, but occasionally it is slow for periods of 10 to 20 minutes, four or five times a day. After you undertake some performance analysis you identify that the slowdowns occurs whenever certain management reports are run against your data warehouse. This slow down is caused because excessive memory and CPU cycles are used to process the data required for these reports. The Resource Governor feature of SQL Server 2008 can help you solve this problem. You can set up the Resource Governor to control the CPU and memory consumed by data warehouse queries. Let me walk through how you would do this.
Controlling Resource Usage with Resource Governor Our goal for setting up the Resource Governor will be to make sure we can throttle resources based on the following requirements:
The first step in setting up the Resource Governor is to create a function that can be used to classify which workload group a session should be associated with. This function is known as a classifier function. The function is used to determine what workload group a session should be associated with. You need a way to clearly identify a workload if you want to control their resources with the Resource Governor. A number of system functions can be used to identify users and applications to map them to the appropriate workload group. Here a partial list of some system functions that could be used in your classifier functions: HOST_NAME(), APP_NAME(), SUSER_NAME, SUSER_SNAME(), IS_SERVERROLEMEMBER(), and IS_MEMBER(). For the situation identified in my scenario above here is my classifier function to identify when the DataWarehouse workload group should be used:
Here you can see that the DataWarehouse_WG workload group is returned from this function when the current date is between 8 a.m. and 5 p.m., Monday through Friday, when the user is not equal to OrderEntry. Note I used the SUSER_NAME function to identify the sessions that are associated with my Order Entry System. By using this function the Resource Governor will be able to make sure all users that are not using the Order Entry system will be classified as being in the DataWarehouse workload group. You need to make sure your classifier function is setup correctly or it can lead to an unresponsive system. If this happens you will either need to use the Dedicated Administrator Connection (DAC) or run SQL Server in single user mode in order to disable the Resource Governor until you can fix the classifier function. Once your classifier function is set up you can move on and define a Resource Pool. A Resource Pool needs to be defined so you can identify the minimum and maximum resources that all queries in the pool can consume. Here is my Resource Pool definition.
Here I have identified a Resource Pool named DataWarehouse_RP, where the maximum amount of CPU that can be used is only 10 percent and the maximum memory percentage is 20 percent. The last thing I need to specify is the Workload Group that will be associated with my DateWarehouse_RP Resource Pool. To do this I run the following command:
With this command I have defined a Work Group named DataWarehouse_WG. This work group further constrains individual queries in this workload group to not use more than 25 percent of the memory that the workload group is authorized.
Now once I have this done, all that I need to do is make sure that my classifier function is associated with the Resource Governor. To do that I would run the following command:
Just because I have ALTER'd the resource governor to have a new classifier function doesn't mean it will be enabled. I still need to apply this configuration change to make the Resource Governor use this classifier function. To do that I need to run the following command:
If for some reason I wanted to turn off the Resource Governor I could execute the following command:
Note that you will not be able to drop and re-create your classifier function while it is the classifier function for Resource Governor. You cannot even ALTER your classifier while it is associated with the Resource Governor. In addition, disabling the Resource Governor still doesn't allow you to ALTER, or DROP the Resource Governor Classifier function. If you want to change your classifier function you will first need to associate the Resource Governor with a different classifier function, or set the classifier function to NULL by using the following statement:
Dynamic Management Views for Resource Governor The first DMV is sys.dm_resource_governor_configuration. This DMV allows you to identify which classifier function is being used and whether or not there is a pending reconfiguration required. There are two columns returned by this DMV: classifier_function_id, is_ reconfiguration_pending. If the classifier_function_id value is 0 then no classifier function has been associated with the Resource Governor. When the is_reconfiguration_pending value is 0 there are no configurations pending, but if it is "1" then some pending configuration changes are waiting to be activated. To activate pending changes, as mentioned above, requires you to run the "ALTER RESOURCE GOVENOR RECONFIGURE" command, or you need to restart your instance. The next DMV is sys.dm_resource_governor_resource_pools. This DMV allows you to obtain some statistics on how your Resource Pools have been consuming resources. You can use this DMV to determine how much memory and CPU your pools have consumed over time. The last DMV provided is sys.dm_resouce_governor_workload_groups. This DMV returns information about how individual workloads have been consuming resource, and there current configuration settings. You can use this DMV in conjunction with sys.dm_resource_governor_resource_pools to get a good picture of how all your workload groups and resources pools are doing to help control your SQL Server resources.
Conclusion |
|||
LEARN