{"id":20,"date":"2008-05-13T10:06:21","date_gmt":"2008-05-13T01:06:21","guid":{"rendered":"http:\/\/www.jhouseconsulting.com\/index.php\/jhouseconsulting\/2008\/05\/13\/processor-scheduling\/"},"modified":"2008-07-22T12:51:24","modified_gmt":"2008-07-22T03:51:24","slug":"processor-scheduling","status":"publish","type":"post","link":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/2008\/05\/13\/processor-scheduling-20","title":{"rendered":"Processor Scheduling"},"content":{"rendered":"<p>Multi-tasking Operating Systems just give the illusion that they\u2019re doing things in parallel. In reality, the CPUs rapidly skip from task to task using various algorithms and heuristics, making one think the processes truly are running simultaneously. The choice of scheduling algorithm can be immensely important.<!--more--><\/p>\n<p>In a nutshell the processors are allowed to spend finite chunks of time per process. This &#8220;time&#8221; is referred to as quanta. The quantum is simply the amount of time the CPU will spend on the task. Every time the CPU switches to a new process, there is what\u2019s called a <em>context switch<\/em>. Context Switches\u00a0are computationally expensive,\u00a0\u00a0and we all know how bad excessive context swtiching is in any environment, more so in a Terminal Services environment. So obviously we need to avoid excessive context switching but still maintain the illusion of concurrency.<\/p>\n<p>Thomas Koetzing wrote a great article on <a target=\"_blank\" href=\"http:\/\/www.thomaskoetzing.de\/index.php?option=com_content&amp;task=view&amp;id=196&amp;Itemid=209\">Understanding and Troubleshooting context switches<\/a>.<\/p>\n<p>There is some excellent information on how Windows manages Processes and Threads in the updated <em>Windows Internals, Fifth Edition<\/em> book by Mark E. Russinovich and David A. Solomon with Alex Ionescu. You can still download chapter 6\u00a0from the Fourth Edition titled &#8220;<a target=\"_blank\" href=\"http:\/\/download.microsoft.com\/download\/5\/b\/3\/5b38800c-ba6e-4023-9078-6e9ce2383e65\/C06X1116607.pdf\">Processes, Threads, and Jobs<\/a>&#8220;. It&#8217;s a great read!<\/p>\n<p>Changing the processor scheduling option modifies the Win32PrioritySeparation value under the HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Control\\PriorityControl key, which consists of 6 bits (AABBCC)&#8230;<\/p>\n<ul>\n<li>Where\u00a0AA =<br \/>\n01 &#8211; longer timeslice interval<br \/>\n10 &#8211; shorter intervals<\/li>\n<li>Where\u00a0BB =<br \/>\n01 &#8211; timeslice can have variable length<br \/>\n10 &#8211; timeslice has fixed length<\/li>\n<li>Where\u00a0CC =<br \/>\n00 &#8211; foreground\/background processes have same priority<br \/>\n01 &#8211; foreground process gets 2 x boost compared to background process\u00a0<br \/>\n10 &#8211; foreground process gets 3 x boost compared to background process<\/li>\n<\/ul>\n<p>When you set the performance option for processor scheduling\u00a0in the GUI, you only see two possible choices for the duration of the timeslice quantum:<br \/>\n1) <em>Programs<\/em>: value is 38 decimal, binary is 100110 = shorter intervals, variable timeslice length, 3 x boost<br \/>\n2) <em>Background Services<\/em>: value is 24 decimal, binary is 011000 = longer timeslice interval, timeslice fixed length, no boost<\/p>\n<p>Neither of these settings are optimal for a Terminal Server, although the <em>Programs<\/em> option is the better of the two simply because shorter timeslices are mandatory for a Terminal Server environment.<\/p>\n<p>If using CPU Utilization Management Feature that was introduced with Citrix Presentation Server 4.0 Enterprise Edition and above, the 3 x\u00a0boost for the default <em>Programs<\/em> value makes this feature somewhat less effective. In these circumstances the variable timeslice length is often better fixed. Under these conditions it is suggested that the optimum value\u00a0may indeed be\u00a040 decimal, 101000 binary. That gives us small, fixed length timeslices, allowing the CPU Utilization Management Feature to efficiently do its job by\u00a0giving each user a fair share of the CPU by modifying the normal job priority scheduling in the operating system.<\/p>\n<p>For further information refer to an FAQ on <a target=\"_blank\" href=\"http:\/\/support.citrix.com\/article\/CTX106021\">the CPU Utilization Management Feature and the CPU Rebalancer Services<\/a>.<\/p>\n<p>Ironically, after setting \u00a0the Win32PrioritySeparation value to 40 decimal you will receive the following message in the Application Event Logs once the &#8220;Citrix CPU Utilization Mgmt\/Resource Mgmt&#8221; service is next restarted.<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<p>Event Type:\u00a0Warning<br \/>\nEvent Source:\u00a0CTXCPUUtilMgmt<br \/>\nEvent Category:\u00a0(1)<br \/>\nEvent ID:\u00a01591<br \/>\nDate:\u00a0\u00a022\/03\/2008<br \/>\nTime:\u00a0\u00a012:34:28 AM<br \/>\nUser:\u00a0\u00a0N\/A<br \/>\nComputer:\u00a0CTX001<br \/>\nDescription:<br \/>\nWindows is using a custom priority separation value and CPU Utilization Management performance may be degraded. To optimize CPU Utilization Management performance, on the Advanced tab of the System Properties dialog, open Performance Options and select Background services. Then restart the CPU Utilization Management service.<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<p>This seems to be logged if the Win32PrioritySeparation value is set to anything other than 26 Hex (38 Decimal), 18 Hex (24 Decimal), 2 or 0. Bizare! Notice how the description suggests using Background services. Doesn&#8217;t it\u00a0then contradict itself by allowing a setting other than 18Hex? I think this is a badly worded warning message, and can be seen as misleading.<\/p>\n<p>However, if you are not using Presentation Server,\u00a0a version\/edition that supports this feature, or a 3rd Party CPU Management application, then the <em>Programs<\/em> settings is\u00a0a better choice than <em>Background Services<\/em> purely from the aspect of shorter timeslices.<\/p>\n<p>I set this in a custom Group Policy ADM template as per the following:<\/p>\n<p>CLASS MACHINE<br \/>\n\u00a0 CATEGORY &#8220;Terminal Server Tuning&#8221;<br \/>\n\u00a0\u00a0\u00a0 POLICY &#8220;Processor Scheduling&#8221;<br \/>\n\u00a0\u00a0\u00a0 KEYNAME &#8220;System\\CurrentControlSet\\Control\\PriorityControl&#8221;<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0 PART &#8220;Optimise performance for:&#8221; DROPDOWNLIST REQUIRED<br \/>\n\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0 VALUENAME &#8220;Win32PrioritySeparation&#8221;<br \/>\n\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 ITEMLIST<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 NAME &#8220;Programs&#8221; VALUE NUMERIC 38 DEFAULT<br \/>\n\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 NAME &#8220;Background Services&#8221; VALUE NUMERIC 24<br \/>\n\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 NAME &#8220;Terminal Server Optimised&#8221; VALUE NUMERIC 40<br \/>\n\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0 END ITEMLIST<br \/>\n\u00a0 \u00a0\u00a0\u00a0 END PART<br \/>\n\u00a0 \u00a0\u00a0\u00a0 PART &#8220;ONLY set to Terminal Server Optimised if using either the Citrix CPU&#8221; TEXT<br \/>\n\u00a0 \u00a0\u00a0\u00a0 END PART<br \/>\n\u00a0\u00a0 \u00a0\u00a0 PART &#8220;Utilization Management Feature, or a 3rd party CPU Management&#8221; TEXT<br \/>\n\u00a0\u00a0 \u00a0\u00a0 END PART<br \/>\n\u00a0\u00a0 \u00a0\u00a0 PART &#8220;application, such as AppSense Performance Manager, etc.&#8221; TEXT<br \/>\n\u00a0\u00a0 \u00a0\u00a0 END PART<br \/>\n\u00a0\u00a0 \u00a0\u00a0 PART &#8221; &#8221; TEXT<br \/>\n\u00a0\u00a0 \u00a0\u00a0 END PART<br \/>\n\u00a0\u00a0 \u00a0\u00a0 PART &#8220;Note: Be aware that when this is set to Terminal Server Optimised&#8221; TEXT<br \/>\n\u00a0\u00a0 \u00a0\u00a0 END PART<br \/>\n\u00a0\u00a0 \u00a0\u00a0 PART &#8220;the Windows GUI will show this as being set to Background Services.&#8221; TEXT<br \/>\n\u00a0\u00a0 \u00a0\u00a0 END PART<br \/>\n\u00a0\u00a0 \u00a0\u00a0 PART &#8220;This can be misleading when auditing a deployment. Therefore,&#8221; TEXT<br \/>\n\u00a0\u00a0 \u00a0\u00a0 END PART<br \/>\n\u00a0\u00a0 \u00a0\u00a0 PART &#8220;always check the actual Win32PrioritySeparation setting in the&#8221; TEXT<br \/>\n\u00a0\u00a0 \u00a0\u00a0 END PART<br \/>\n\u00a0\u00a0 \u00a0\u00a0 PART &#8220;registry.&#8221; TEXT<br \/>\n\u00a0\u00a0 \u00a0\u00a0 END PART<br \/>\n\u00a0 \u00a0 END POLICY ; Processor scheduling<br \/>\n\u00a0 END CATEGORY ; Terminal Server Tuning<\/p>\n<p>This information was compiled after reviewing many forum posts and articles written by some of the\u00a0most respected\u00a0Server Based Computing experts.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Multi-tasking Operating Systems just give the illusion that they\u2019re doing things in parallel. In reality, the CPUs rapidly skip from task to task using various algorithms and heuristics, making one think the processes truly are running simultaneously. The choice of scheduling algorithm can be immensely important.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[35],"tags":[416,43,44,42],"class_list":["post-20","post","type-post","status-publish","format-standard","hentry","category-os-tuning","tag-citrix","tag-processor-scheduling","tag-terminal-server","tag-win32priorityseparation"],"aioseo_notices":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/posts\/20","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/comments?post=20"}],"version-history":[{"count":0,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/posts\/20\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/media?parent=20"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/categories?post=20"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/tags?post=20"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}