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

ID: Q186628


The information in this article applies to:
  • Microsoft Windows NT Server version 4.0, Terminal Server Edition

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

To modify the Registry:

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).

  1. Run Regedt32.exe and locate the following key:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\Current
          Version\TerminalServer\Compatibility\Applications 


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

  3. 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 


  4. With the SETUP subkey highlighted, 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.


  5. With the Applications subkey highlighted, choose 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.


  6. To copy the values from the SETUP subkey, select your new subkey (for example, MYAPP) and choose Restore from the Registry pull-down menu. Choose the filename you created in Step 3. Click Yes when the warning dialog box is displayed. Your new application subkey now has the same values as the SETUP subkey.


  7. You must now fine-tune the values for your application. The values are described in the following sections:


Bad Application Registry Values

The default values for the bad application settings are:

   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:

   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


  5. The value is now converted to 0xc8, the hexadecimal equivalent of 200 decimal.
NOTES:

  1. To modify polling detection for MS-DOS applications, use the DOSKBD utility. For more information, see the following article in the Microsoft Knowledge Base:
    Q186560 Modifying DOS Application Keyboard Polling Detection


  2. 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.


Additional query words:

Keywords :
Version : WinNT:4.0
Platform : winnt
Issue type : kbinfo


Last Reviewed: July 19, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.