InformIT

Monitoring and Optimizing Apps on Dual-Core and Multiprocessor Systems

Date: Apr 28, 2006

Return to the article

Kurt Hudson explains tricks to optimize applications on multiprocessor computers, even if those applications were developed without such systems in mind.

Multiprocessor computers have been around for quite a while, but dual-core processors are a relatively new offering. Both Intel and AMD dual-core processors are showing up in consumer-level servers, desktop systems, and laptops. A dual-core processor is essentially a single CPU chip that’s actually two processors. Since it’s really a single plug-in chip, though, you see only a single CPU chip plugged in when looking at the motherboard.

If you’re using a Windows 2000, XP Professional, or Windows Server operating system, you can open the Performance tab in Windows Task Manager (as shown in Figure 1) to see that multiple processors are recognized by the operating systems. Notice that the CPU Usage History has two windows; each window represents a processor (CPU).

Figure 1

Figure 1 Performance tab showing two processors.

If you have a system with two dual-core processors, the CPU Usage History will have four windows, one for each processor, as shown in Figure 2.

Figure 2

Figure 2 Performance tab showing four processors.

Setting Process Priority

Whether you have multiple physical processors or dual-core processors, the operating system treats them as separate processors. Multitasking operating systems receive processing requests from applications. These requests are known as threads. The applications run as processes and the operating system schedules those processes. You can see the running processes by clicking the Processes tab. You can affect how applications run by making changes to the processes listed there. The adjustments that you can make include changing the base priority at which a process spawns threads, as well as setting the processor affinity of the process. Both types of adjustments affect application performance.

The Windows 32-bit operating systems schedule threads using 32 priority levels, numbered from 0 to 31. The highest-numbered thread is processed first. As threads wait to be processed, their priority levels are increased. The base application priority determines the priority level at which threads begin. As a Windows administrator, you can adjust the base priority of a process to a variety of settings. The following table shows the priority levels for each of these definable settings.

Setting

Priority Level

Realtime

24

High

13

AboveNormal

9

Normal

8

BelowNormal

7

Low

4

If you right-click a process on the Task Manager’s Processes tab and select Set Priority, you’ll see all six priority options. You can set the Realtime priority only when you’re logged onto a system with administrative rights.

When might you want to change the priority of a running process? If you have a an application that you expect to run for a long time, but you want to minimize the impact of that application on the computer’s performance while you’re using it, you can set the less important process to run at a BelowNormal or Low priority level. Conversely, if you have a critical application that you want to receive processing time over all other applications on the system, you can set the priority level to AboveNormal or High.

If you want a particular Windows application to always start with a base priority other than normal, you can use the Start command in a batch file to always launch that application at a higher priority. For example, if you wanted to run an application named PriorityOne at a high priority, you could create a batch file using the start command:

start /high c:\priorityone.exe

This command could be used to start the application at a high priority.

Setting Affinity

By default, the Windows operating systems set processes to run on all available processors. If you have multiple processors or one or more dual-core processors in your system, you can control the processor(s) on which an application runs. On the Process tab of the Task Manager, right-click the desired process and select the Set Affinity option to open a dialog box like the one shown in Figure 3.

Figure 3

Figure 3 The Processor Affinity dialog box allows you to specify on which CPUs a process can be run.

Although you can use the Processor Affinity dialog box to control the CPUs on which applications run, many applications are also multiprocessor-aware. For example, Microsoft SQL Server 2000 and later versions allow you to configure processor priority within the application (see the Microsoft SQL Server 2000 Analysis Services Operations Guide for more information).

Using the RunFirst Command-Line Tool

If you have an application that’s not multiprocessor-aware, it may fail to run properly on a multiprocessor system. If that happens, you can use a free utility called RunFirst, which is a command-line tool that lets you start an application on the first processor of a multiprocessor system. The application does the same thing that you can do by using the Task Manager’s Set Affinity command, but because RunFirst is an executable file, you can run it from a batch file.

For example, assume that I have an application that I’ve noticed stops responding on my multiprocessor system, but runs well on my single-processor systems. Let’s say that the application is named OldApp.exe and is located in the C:\Apps\OldApps folder.

The RunFirst.exe application is located in the C:\Apps\RunFirst folder. I could create a batch file or even a Windows shortcut with this command:

C:\Software\RunFirst\RunFirst.exe C:\Software\OldApps\OldApp.exe

When that batch file or shortcut runs, OldApp.exe starts on the first processor in the system only. You can verify that it’s working properly by opening the Task Manager, right-clicking the OldApp.exe process, and selecting Set Affinity. In the Processor Affinity dialog box, you’ll see that OldApp.exe has a checkmark for only the first processor (see Figure 4).

Figure 4

Figure 4 OldApp.exe running on CPU 0 only.

Using the ImageCFG Utility

Another free application that you can use to specify the processor on which an application is allowed to run is ImageCFG. Unlike RunFirst, ImageCFG allows you to select the process on which your application will run. Continuing with OldApp.exe from the previous example, let’s assume that I want to run OldApp.exe on the second processor. I could run the following command from a command prompt:

ImageCFG 0x2 C:\Software\OldApps\OldApp.exe

This would create an affinity mask for the OldApp.exe application that would set it to run on the second processor only. The processor numbering scheme is simple: 0x1 refers to the first processor; 0x2 the second processor; 0x3 the third, and so on.

In addition to being able to target a specific processor, ImageCFG doesn’t require a batch file or shortcut. You simply run the utility once, and whenever you launch the application in the future, it’s now set to run on the processor you specified.

Windows System Resource Manager

If you want to control applications in a larger environment where you have a Windows Server 2003, Enterprise Edition, or Datacenter Edition server, you might look into the Windows System Resource Manager (WSRM). WSRM enables administrators to manage CPU and memory utilization on a per-process basis in an enterprise network. This allows the administrator to allocate resources among multiple applications on a server according to business priorities. The WSRM is a client/server application and the server application only runs on Windows Server 2003, Enterprise, and Datacenter Editions (32-bit and 64-bit versions). The WSRM client versions can be added to Windows XP and Windows Server 2003 Enterprise and Web Editions. Essentially, the WSRM application must be run on an enterprise-class server, but then can be used to control processes that are running on client and server operating systems that are part of the enterprise network. See the free interactive demonstration at the Microsoft web site.

Conclusions

Many top-of-the-line enterprise applications have built-in controls that allow for application and process customization. Older applications and those marketed to consumers and small to medium-sized businesses often don’t allow you to control process priorities or which CPUs will be utilized. Today, however, it’s not uncommon to see consumers and small business running dual-core systems. To get the most out of this processing power, you can use the built-in start command in Windows operating systems to control the base priority of processes spawned by applications. To limit applications to run on only the first processor in your system, you can use the RunFirst application. If you want to target specific processors on which your applications can run, use ImageCFG. Using these methods will allow you to optimize applications on multiprocessor computers, even if those applications were developed without such systems in mind.

800 East 96th Street, Indianapolis, Indiana 46240