Advanced Topic: Changing Thread Priority to Improve Performance

After observing the threads that use the greatest amount of processor time, monitor the dispatch states of the threads. This will tell you which threads are running and which threads are ready. Most important, monitoring thread states on your system can help you identify which threads are piling up in the queue and which threads are actively running at various times.

The Thread\Thread State counter provided by System Monitor reports the current execution state (also known as dispatch state) of a thread. System Monitor reports thread state as a numeric value from 0 through 7, corresponding to whether the thread is ready, running, terminated, and so on.

Table 7.3 lists the thread states you will typically see.

Table 7.3 Typical Thread States

Thread state

Description

0

Initialized.

1

Ready. The thread is prepared to run on the next available processor.

2

Running.

3

Standby. The thread is about to use the processor.

4

Terminated.

5

Waiting. The thread is not ready to run, typically because another operation (for example, involving I/O) must finish before the thread can run.

6

Transition. The thread is not ready to run because it is waiting for a resource (such as code being paged in from disk).

7

Unknown. The thread is in an unknown state.

To determine which threads are contending for the processor, track the states of all threads in the system using System Monitor. Figure 7.15 shows a histogram. The vertical maximum for the chart is set to 10 to make it easier to see the values; an alternative for easier viewing is to display the thread-state values in a report view.

Cc938612.FNED15(en-us,TechNet.10).gif

Figure 7.15 Display of Thread States

Notice that the preceding figure plots a thread of the MMC process with the steady value of 2 for running. This is the thread of the System Monitor snap-in that is collecting the data that you are monitoring. As long as System Monitor is running, one of its threads will be shown to be running. Other threads' state values alternate between 1 for ready and 5 for waiting.

Plotting thread-state data in a chart rather than a histogram might make it easier to view the switching of thread states. Note in Figure 7.16 how a process's thread moves from the waiting state (plotted on the chart at 5) to the ready state (plotted on the chart at 1).

Cc938612.FNED16(en-us,TechNet.10).gif

Figure 7.16 Changing Thread States

To find out how long threads remain in a particular state, log Thread\Thread State and, when the log is completed, export it to Microsoft Excel. A sample log is shown in Figure 7.17.

Cc938612.FNED91(en-us,TechNet.10).gif

Figure 7.17 Sample Log Output Viewed in Microsoft Excel

By looking at log output, you can get an idea of the length of time that a thread remains in a state by totaling the number of seconds that elapsed until the thread's state changed. However, it is important to note that, due to the fact that sampling omits some data, you might not see all of the state changes that occur.

In addition, the Thread\Thread Wait State counter and Perfmon4.exe on the Windows   2000 Resource Kit companion CD give you information about why a thread is in a waiting state.

The value reported for Thread Wait Reason is a code. The Counters Help file on the Windows   2000 Resource Kit companion CD provides descriptions for these codes.