{"id":1643,"date":"2006-11-12T11:50:49","date_gmt":"2006-11-12T11:50:49","guid":{"rendered":"http:\/\/neu.koetzingit.de\/kontextwechsel-context-switches-verstehen-und-probleme-damit-beheben\/"},"modified":"2026-06-02T13:33:47","modified_gmt":"2026-06-02T13:33:47","slug":"kontextwechsel-context-switches-verstehen-und-probleme-damit-beheben","status":"publish","type":"post","link":"https:\/\/www.koetzingit.de\/en\/kontextwechsel-context-switches-verstehen-und-probleme-damit-beheben\/","title":{"rendered":"Understanding context switches and troubleshooting related issues"},"content":{"rendered":"<p><span class=\"dropcapmiddle\">S<\/span>Have you ever heard of context switches? If so, it\u2019s probably because you\u2019re an administrator for a Citrix Presentation Server farm. This isn\u2019t a problem specific to Citrix, but context switches are among the standard metrics monitored by Citrix Resource Manager and apparently trigger alerts quite frequently.<\/p>\n<p>Other systems may also have issues with context switching, but without monitoring, no one will notice.<\/p>\n<p><!--more--><\/p>\n<h3><span class=\"label label-success\">Understanding changes in context<\/span><\/h3>\n<p>I won't go into too much detail here; this description is simply meant to explain the basics of context switching in a straightforward way.<\/p>\n<p>Processes consist of so-called \u201ethreads\u201c that perform the actual work. Threads are scheduled and executed on the system CPU (on a single CPU, not on all CPUs in the system), and only one thread can be executed per CPU at a time. In addition, a process can have multiple threads. The specified duration of execution is called a \u201equantum,\u201c but this does not mean that a thread is necessarily allowed to use the entire quantum, nor that the thread\u2019s work is finished once the quantum has elapsed. However, when the quantum ends, a context switch to the next scheduled thread is performed (this is just one reason for a context switch; premature termination is also a context switch).<\/p>\n<p>If the performance counter for context switches (per second) shows a high value, it means that threads have less time to do their work, which can cause the performance of the entire system to decline.<\/p>\n<h3>Two other definitions of context switching:<\/h3>\n<p><strong>Microsoft<\/strong><br \/>\u201eThe average number of times per second that the processor switches context between threads. A high rate indicates that many threads are competing for processor time.\u201c<\/p>\n<p><strong>Windows Internals<\/strong><br \/>\u201eContext switch refers to the process in which the temporary processor state of the active thread is saved, the temporary processor state of another thread is loaded, and execution of the new thread is started.\u201c<\/p>\n<p>\u00a0<\/p>\n<h3><span class=\"label label-success\">Reason for high context-switching rates<\/span><\/h3>\n<p>Often, the problem is caused by a swap file that is too small or one that cannot grow dynamically. Another possible cause is the write cache of the (RAID) controller, which can be managed using the Microsoft utility (or the manufacturer's tool). <a href=\"http:\/\/support.microsoft.com\/kb\/811392\" target=\"_blank\" rel=\"noopener noreferrer\">dskcache<\/a> can be adjusted. High active rates can also be caused by inefficient hardware or poorly programmed applications.<\/p>\n<p>\u00a0<\/p>\n<h3><span class=\"label label-success\">Troubleshooting issues with context switches<\/span><\/h3>\n<p>As is often the case, there are various ways to identify and resolve the issue, but the main goal is to pinpoint the process that is causing a high rate of context switching. It is important to note that better hardware may be required.<\/p>\n<p>How can you determine the current value of context switches for the system? The answer can be found using Microsoft\u2019s Performance Monitors (perfmon.msc) under System\/Context Switches or Threads\/Context Switches. If you look at context switches based on threads in Performance Monitor, you\u2019ll find that it\u2019s not easy to identify the process with high rates.<\/p>\n<p>Sysinternals is much better in this regard <a href=\"http:\/\/www.sysinternals.com\/Utilities\/ProcessExplorer.html\" target=\"_blank\" rel=\"noopener noreferrer\">Process Explorer<\/a> (free of charge). By default, however, Process Explorer does not display context switches and must first be enabled.<\/p>\n<p>You can do this by going to View | Select Columns | Process Performance | and enabling \"Context Switches\" and \"Context Switch Delta\"<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1639\" src=\"http:\/\/www.koetzingit.de\/wp-content\/uploads\/2006\/11\/cspe01.png\" width=\"250\" height=\"343\" border=\"0\" hspace=\"6\"  alt=\"Cspe01\"  title=\"Understanding context switches and troubleshooting related issues\" srcset=\"https:\/\/www.koetzingit.de\/wp-content\/uploads\/2006\/11\/cspe01.png 250w, https:\/\/www.koetzingit.de\/wp-content\/uploads\/2006\/11\/cspe01-219x300.png 219w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\" \/>\u00a0 <img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1640\" src=\"http:\/\/www.koetzingit.de\/wp-content\/uploads\/2006\/11\/cspe02.png\" width=\"250\" height=\"343\" border=\"0\" hspace=\"6\"  alt=\"Cspe02\"  title=\"Understanding context switches and troubleshooting related issues\" srcset=\"https:\/\/www.koetzingit.de\/wp-content\/uploads\/2006\/11\/cspe02.png 250w, https:\/\/www.koetzingit.de\/wp-content\/uploads\/2006\/11\/cspe02-219x300.png 219w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\" \/><\/p>\n<p>Both values should now be visible for each process in the main window of Process Explorer. The Context Switches column shows the total number of switches since the system started. Sort this column by the highest value and look for a) high values and b) rapidly increasing values. Both are good indicators of processes with high context switches.\u00a0<\/p>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1641\" src=\"http:\/\/www.koetzingit.de\/wp-content\/uploads\/2006\/11\/cspe03.png\" width=\"350\" height=\"403\" border=\"0\" hspace=\"6\"  alt=\"Cspe03\"  title=\"Understanding context switches and troubleshooting related issues\" srcset=\"https:\/\/www.koetzingit.de\/wp-content\/uploads\/2006\/11\/cspe03.png 350w, https:\/\/www.koetzingit.de\/wp-content\/uploads\/2006\/11\/cspe03-261x300.png 261w\" sizes=\"auto, (max-width: 350px) 100vw, 350px\" \/><\/td>\n<\/tr>\n<tr>\n<td>Process Explorer \u2013 Context Switches Column<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u00a0<\/p>\n<p>Next, check the CSwitch Delta column, as it displays the number of context switches per update interval in Process Explorer (with an \u201eupdate speed\u201c of 1 second, this represents the number of context switches per second). If the process was found, you should investigate why it has such a high number of context switches.<\/p>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1642\" src=\"http:\/\/www.koetzingit.de\/wp-content\/uploads\/2006\/11\/cspe04.png\" width=\"350\" height=\"402\" border=\"0\" hspace=\"6\"  alt=\"Cspe04\"  title=\"Understanding context switches and troubleshooting related issues\" srcset=\"https:\/\/www.koetzingit.de\/wp-content\/uploads\/2006\/11\/cspe04.png 350w, https:\/\/www.koetzingit.de\/wp-content\/uploads\/2006\/11\/cspe04-261x300.png 261w\" sizes=\"auto, (max-width: 350px) 100vw, 350px\" \/><\/td>\n<\/tr>\n<tr>\n<td>Process Explorer \u2013 CSwitches Deltas Column<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u00a0<\/p>\n<h3><span class=\"label label-success\">Values for \u201epoor\u201c context switching<\/span><\/h3>\n<p>The default value for the \u201eRed Alert\u201c context switch in Citrix Resource Manager is 14,000, but this applies to a single CPU. The value is per processor, so with two CPUs the value should be 28,000, with three CPUs 42,000, and for a quad-CPU system 56,000. These are still just baseline values, and to obtain an accurate value, the system must be monitored over a certain period of time.<\/p>\n<p>At BriForum 2006 EU, I spoke with <a href=\"http:\/\/www.tmurgent.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Tim Mangan<\/a> We talked, and he said that context shifts shouldn't be given too much attention.<br \/>\u00a0<\/p>\n<h3><span class=\"label label-success\">References<\/span><\/h3>\n<ul>\n<li>\n<p>Sysinternals Process Explorer<br \/><a href=\"http:\/\/technet.microsoft.com\/sysinternals\/bb896653.aspx\">http:\/\/technet.microsoft.com\/sysinternals\/bb896653.aspx<\/a><\/p>\n<\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Schon mal von Kontextwechsel (context switches) geh\u00f6rt? Wenn ja, dann sicher weil Sie Administrator f\u00fcr eine Citrix Presentation Server Farm [&hellip;]<\/p>\n","protected":false},"author":1755,"featured_media":1590,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[11],"tags":[228,79,32,229,230,232,231],"class_list":["post-1643","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-understanding-de","tag-content","tag-explorer","tag-microsoft","tag-proess","tag-switch","tag-sysinternals","tag-wechsel"],"uagb_featured_image_src":{"full":["https:\/\/www.koetzingit.de\/wp-content\/uploads\/2016\/11\/news-next28-journal-sq.jpg",360,360,false],"thumbnail":["https:\/\/www.koetzingit.de\/wp-content\/uploads\/2016\/11\/news-next28-journal-sq-150x150.jpg",150,150,true],"medium":["https:\/\/www.koetzingit.de\/wp-content\/uploads\/2016\/11\/news-next28-journal-sq-300x300.jpg",300,300,true],"medium_large":["https:\/\/www.koetzingit.de\/wp-content\/uploads\/2016\/11\/news-next28-journal-sq.jpg",360,360,false],"large":["https:\/\/www.koetzingit.de\/wp-content\/uploads\/2016\/11\/news-next28-journal-sq.jpg",360,360,false],"1536x1536":["https:\/\/www.koetzingit.de\/wp-content\/uploads\/2016\/11\/news-next28-journal-sq.jpg",360,360,false],"2048x2048":["https:\/\/www.koetzingit.de\/wp-content\/uploads\/2016\/11\/news-next28-journal-sq.jpg",360,360,false],"trp-custom-language-flag":["https:\/\/www.koetzingit.de\/wp-content\/uploads\/2016\/11\/news-next28-journal-sq.jpg",12,12,false]},"uagb_author_info":{"display_name":"Thomas K\u00f6tzing","author_link":"https:\/\/www.koetzingit.de\/en\/author\/thomas-koetzing\/"},"uagb_comment_info":0,"uagb_excerpt":"Schon mal von Kontextwechsel (context switches) geh\u00f6rt? Wenn ja, dann sicher weil Sie Administrator f\u00fcr eine Citrix Presentation Server Farm [&hellip;]","_links":{"self":[{"href":"https:\/\/www.koetzingit.de\/en\/wp-json\/wp\/v2\/posts\/1643","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.koetzingit.de\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.koetzingit.de\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.koetzingit.de\/en\/wp-json\/wp\/v2\/users\/1755"}],"replies":[{"embeddable":true,"href":"https:\/\/www.koetzingit.de\/en\/wp-json\/wp\/v2\/comments?post=1643"}],"version-history":[{"count":1,"href":"https:\/\/www.koetzingit.de\/en\/wp-json\/wp\/v2\/posts\/1643\/revisions"}],"predecessor-version":[{"id":1923,"href":"https:\/\/www.koetzingit.de\/en\/wp-json\/wp\/v2\/posts\/1643\/revisions\/1923"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.koetzingit.de\/en\/wp-json\/wp\/v2\/media\/1590"}],"wp:attachment":[{"href":"https:\/\/www.koetzingit.de\/en\/wp-json\/wp\/v2\/media?parent=1643"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.koetzingit.de\/en\/wp-json\/wp\/v2\/categories?post=1643"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.koetzingit.de\/en\/wp-json\/wp\/v2\/tags?post=1643"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}