Microsoft KB Archive/186628

= Performance Tuning CPU Use for 16 and 32-bit Windows Applications =

Article ID: 186628

Article Last Modified on 11/1/2006

-

APPLIES TO


 * Microsoft Windows NT Server 4.0, Terminal Server Edition

-



This article was previously published under Q186628



IMPORTANT: This article contains information about editing the registry. Before you edit the registry, make sure you understand how to restore it if a problem occurs. For information about how to do this, view the "Restoring Registry Key" Help topic in Regedit.exe or the "Restoring a Registry Key" Help topic in Regedt32.exe.



SUMMARY
Windows 16-bit or 32-bit applications may use too much CPU time, even when they are idle (no keyboard or mouse events). Terminal Server's registry can be modified to detect this behavior, suspending application execution and allowing other applications to use the CPU, making multitasking much more efficient.



MORE INFORMATION
WARNING: Using Registry Editor incorrectly can cause serious problems that may require you to reinstall your operating system. Microsoft cannot guarantee that problems resulting from the incorrect use of Registry Editor can be solved. Use Registry Editor at your own risk.

For information about how to edit the registry, view the "Changing Keys And Values" Help topic in Registry Editor (Regedit.exe) or the "Add and Delete Information in the Registry" and "Edit Registry Data" Help topics in Regedt32.exe. Note that you should back up the registry before you edit it. If you are running Windows NT, you should also update your Emergency Repair Disk (ERD).

To modify the registry, perform the following steps:  Run Regedt32.exe and locate the following key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\TerminalServer\Compatibility\Applications

NOTE: The above registry key is one path; it has been wrapped for readability.

  Double-click the Applications subkey to reveal several pre-defined settings. Select SETUP under the Applications subkey. The following values are displayed on the right side of the Registry Editor window: FirstCountMsgQPeeksSleepBadApp:REG_DWORD:0xf

Flags:REG_DWORD:0x8 MsgQBadAppSleepTimeInMillisec:REG_DWORD:0 NthCountMsgQPeeksSleepBadApp:REG_DWORD:0x5  With the Setup subkey highlighted, click to select Save Key from the Registry pull-down menu. The filename can be anything, such as Setup.reg. When the setup values are saved, create a subkey for your application. With the Applications subkey highlighted, click to select Add Key on the Edit pull-down menu. Set the Key Name field to the name of the executable in question, minus the extension. For example, for the application Myapp.exe, type MYAPP in the Key Name field. Leave the Class field blank. Click OK. To copy the values from the Setup subkey, click to select your new subkey (for example, MYAPP) and click to select Restore from the Registry pull-down menu. Click to choose the filename you created in Step 3. Click Yes when the warning dialog box displays. Your new application subkey now has the same values as the Setup subkey. You must now fine-tune the values for your application. The values are described in the following sections:</li></ol>

Bad Application Registry Values
The default values for the bad application settings are: <pre class="fixed_text">FirstCountMsgQPeeksSleepBadApp = 0xf MsgQBadAppSleepTimeInMillisec = 0x1 NthCountMsgQPeeksSleepBadApp = 0x5 Flags: 0x8 FirstCountMsgQPeeksSleepBadApp is the number of times the application must query the message queue before Terminal Server decides that it is ill-behaved. Decrease this value to put the application to sleep more often, so it uses less CPU time.

MsgQBadAppSleepTimeInMillisec is the number of milliseconds the application is suspended when Terminal Server has decided that it is ill-behaved. Increase this value to use less CPU time. If this value is zero, polling detection is disabled.

NthCountMsgQPeeksSleepBadApp - After the application is determined to be "bad," this setting is the number of times the application must query the message queue before it is suspended again. Decrease this value to use less CPU time.

Flags is set to a value corresponding to the type of Windows application. Valid values are: <pre class="fixed_text">0x4 for Win16 applications only 0x8 for Win32 applications only 0xC for either Win16 or Win32 applications

Bad Application Settings
All values are expressed in hexadecimal numbers. When changing the values, first click the Decimal button and input the decimal value. For instance, if you want the MsgQBadAppSleepTimeInMillisec value to be set to 200 milliseconds, perform the following steps:
 * 1) Double-click MsgQBadAppSleepTimeInMillisec.
 * 2) Click the Decimal radio button.
 * 3) Enter 200 in the Data field.
 * 4) Click OK. The value is now converted to 0xc8, the hexadecimal equivalent of 200 decimal.

NOTES: <ul> To modify polling detection for MS-DOS applications, use the DOSKBD utility. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

186560 Modifying DOS application keyboard polling detection

</li> When tuning these parameters, make sure Performance Monitor is running. These parameters will affect the amount of CPU used by an application. These parameters usually trade off CPU usage versus application responsiveness.</li> The registry entries that are mentioned in this article do not apply to Windows 2000 Terminal Services, Windows XP, or Windows 2003 Terminal Services.</li></ul>

Keywords: kbinfo KB186628

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.