This rule tracks context switching, which occurs whenever a one thread ceases to execute on a processor and another thread is swapped in.
Context switching introduces an overhead due to the cost of setting up the new thread's execution environment, and swapping in its stack.
When the rate of context switching is very high, the system may be doing more work switching between threads instead of executing them, causing poor system-wide performance.
Diagnostics
This rule will identify whether context switching is being caused by the application itself, or other applications on the server.
If the context switching is due to the application, the diagnostics will then identify the code most likely responsible for the elevated context switching rate.
Pay particular attention to the "Running" threads, as these are the threads that are either executing or waiting to be executed, and thereby contributing to the context switching.
In some cases, it is possible that threads marked "Waiting" are also contributing to context switching if the wait times are short, and threads frequently exit the Wait state to be executed.
As example is a thread that executes Thread.Sleep(10), waiting for a very short time before continuing to execute. This thread may show up as Waiting during the analysis, but is likely to contribute to context switching a short time later. A similar pattern can be caused by threads experiencing short waits on locks, semaphores, producer/consumer queues, and so forth.
Improving this score
To reduce context switching, reduce the number of Runnable threads in the application (the threads actively executing or waiting to execute on a processor). Use the diagnostics to identify the code that is executing on the majority of Runnable threads, and implement optimizations to reduce the number of running threads.
Proactive guidance
If you are on a Business plan, we may offer additional guidance to help you optimize your application and improve its performance. To find out more, contact support.
Context switching introduces an overhead due to the cost of setting up the new thread's execution environment, and swapping in its stack.
When the rate of context switching is very high, the system may be doing more work switching between threads instead of executing them, causing poor system-wide performance.
Diagnostics
This rule will identify whether context switching is being caused by the application itself, or other applications on the server.
If the context switching is due to the application, the diagnostics will then identify the code most likely responsible for the elevated context switching rate.

Pay particular attention to the "Running" threads, as these are the threads that are either executing or waiting to be executed, and thereby contributing to the context switching.
In some cases, it is possible that threads marked "Waiting" are also contributing to context switching if the wait times are short, and threads frequently exit the Wait state to be executed.
As example is a thread that executes Thread.Sleep(10), waiting for a very short time before continuing to execute. This thread may show up as Waiting during the analysis, but is likely to contribute to context switching a short time later. A similar pattern can be caused by threads experiencing short waits on locks, semaphores, producer/consumer queues, and so forth.
Improving this score
To reduce context switching, reduce the number of Runnable threads in the application (the threads actively executing or waiting to execute on a processor). Use the diagnostics to identify the code that is executing on the majority of Runnable threads, and implement optimizations to reduce the number of running threads.
Proactive guidance
If you are on a Business plan, we may offer additional guidance to help you optimize your application and improve its performance. To find out more, contact support.
More resources
Want to learn the best techniques for managing your IIS web server? Join our how-to newsletter.
Want to get the best tool for troubleshooting and tuning your web apps? Try LeanSentry free for 14 days.