27 Jan 2011

Working with the Windows System Resource Manager (Part 2)

Creating a CPU Allocation Policy 

Let's begin by talking about how to create a CPU resource allocation policy. This policy will be used to control the maximum amount of CPU time that an application can consume. Begin the process by opening the Windows System Resource Manager console. When the console opens, right click on the Resource Allocation Policies container and select the New Resource Allocation Policy command from the resulting shortcut menu. When you do, Windows will open the New Resource Allocation Policy dialog box, shown in Figure A.


Figure A: This dialog box is used to define a new resource allocation policy

The first thing that you must do is to enter a name for the new policy. Since you might eventually have multiple policies designed to regulate CPU usage (all for different applications), it's a good idea to give the policy a descriptive name. For example, you might give the policy a name that's related to the application that the policy is intended to regulate. Of course if you intend to use the policy to regulate multiple applications, then you would probably want to base the policy name on what the policy does rather than on the name of an application that the policy applies to.

After you name the new policy, you must assign it at least one process matching criteria. This is just Microsoft speak for assigning the policy to one or more applications. To do so, click the Add button, and you will see the dialog box that's shown in Figure B.


Figure B: The Add or Edit Resource Allocation Properties sheet allows you to select the application that you want to apply the policy to

The first thing that you will probably notice is the Process Matching Criteria drop down list. This list gives you a choice of selecting either an IIS application pool or one of the applications that you have already defined. In this particular case, I have selected Notepad because it was the application that I defined in Part 1.

Just below the Process Matching Criteria drop down list is a field that allows you to adjust the percentage of processor time allocated to the selected application. The value that you select reflects the maximum amount of CPU time that the application can consume.

If you only have a single policy in place, then you can set the allocated CPU time to anywhere from 0% to 99%. Notice the last line of text in the Figure B. It reflects the remaining CPU percentage given to default allocation. What this means is that if you were to define the policy that allocated 25% of your CPU resources to an application, then only 74% of the machine's total CPU time will be available to other policies. In case you're wondering why the number isn't 75%, it's because the Windows System Resource Manager only allows you to allocate up to 99% of the machine's CPU resources.  At least 1% must be reserved for the Windows operating system.

If CPU time was the only resource that you wanted to allocate as a part of this policy, you would simply click OK twice to create the policy. Rather than calling it quits after allocating CPU resources though, let's take a look at how you would go about allocating memory resources.

Creating a Memory Allocation Policy

If you look at Figure B, you will notice that the properties sheet shown in the figure contains a Memory tab. You can see what this tab looks like in Figure C.


Figure C: The Memory tab allows you to set the maximum memory allocation for the application

As you can see in the figure, this tab allows you to specify the maximum committed memory for each process. To do so, you would simply select the Use Maximum Committed Memory for Each Process check box, and then enter a value in megabytes.

Specifying the maximum committed memory works a little bit differently than specifying the maximum CPU utilization. When we specified the maximum CPU utilization, we were setting an absolute limit. The policy simply would not allow the application to consume more than the specified amount of CPU time. When you specify the maximum committed memory for a process, you are not establishing an absolute limit. The policy does not prohibit additional memory from being consumed. Instead, you must use the If Memory Is Surpassed drop down list to control what happens if the specified memory limit is exceeded.

The drop-down list gives you two options. One option is to stop the application. Although this might be a viable option in some situations, you really have to weigh the pros and cons of using this option. On one hand, if an application is running on your server then that application is obviously running for a reason. That being the case, you probably don't want the server shutting the application down if you can keep from it. On the other hand, suppose that the application in question contains a memory leak and that its excessive memory consumption causes problems with a mission critical application hosted on the same server. In a situation like that, it would probably be a good idea to shut down the application before it has a chance to interfere with the other application.

Your other option is to log an event. If you choose this option the application will not be shut down when the memory limit is exceeded. Instead, an event will just be logged to the Application Log.

The last option on this tab allows you to limit the maximum working set for each process. You would enable this option by selecting the Use Maximum Working Set Limit for Each Process check box  and then entering a threshold value in the place provided.

Setting Resource Allocation Precedence

After you have finished creating your policy, click OK. You will now be returned to the camp New Resource Allocation Policy dialog box. As you can see in Figure D, the policy that we have created now appears on the list of resources.


Figure D: Our new policy now appears on the list of resources

If you look just to the right of the new policy, you'll notice an up arrow and a down arrow icon. You can use these arrows to change the policies precedence. In a case like this in which there is only one policy defined, you really can't adjust the policy precedence. If we have multiple policies, you could use these arrow icons to arrange the order in which the policies are applied.

No comments:

Post a Comment