使用性能计数器来诊断远程桌面会话主机上的应用性能问题Use performance counters to diagnose app performance problems on Remote Desktop Session Hosts

适用于:Windows Server 2019、Windows 10Applies to: Windows Server 2019, Windows 10

最难以诊断的问题之一是应用程序性能 — 应用程序运行缓慢或没有响应。One of the most difficult problems to diagnose is poor application performance—the applications are running slow or don't respond. 传统上,通过收集 CPU、内存、磁盘输入/输出和其他指标来启动诊断,然后使用 Windows Performance Analyzer 等工具来尝试找出问题的原因。Traditionally, you start your diagnosis by collecting CPU, memory, disk input/output, and other metrics and then use tools like Windows Performance Analyzer to try to figure out what's causing the problem. 遗憾的是,在大多数情况下,此数据无法帮助你确定根本原因,因为资源消耗计数器具有频繁且较大的变化。Unfortunately, in most situations this data doesn't help you identify the root cause because resource consumption counters have frequent and large variations. 这样就难以读取数据并将其与报告的问题相关联。This makes it hard to read the data and correlate it with the reported issue. 为了帮助你快速解决应用性能问题,我们添加了可测量用户输入流的一些新性能计数器(可通过 Windows 预览体验计划下载)。To help you solve your app performance issues quickly, we've added some new performance counters (available to download through the Windows Insider Program) that measure user input flows.

备注

“用户输入延迟”计数器仅与以下操作系统版本兼容:The User Input Delay counter is only compatible with:

  • Windows Server 2019 或更高版本Windows Server 2019 or later
  • Windows 10 版本 1809 或更高版本Windows 10, version 1809 or later

用户输入延迟计数器可以帮助你快速确定最终用户 RDP 不良体验的根本原因。The User Input Delay counter can help you quickly identify the root cause for bad end user RDP experiences. 此计数器可测量任何用户输入(如鼠标或键盘使用)在被进程选取之前在队列中停留的时间,并且计数器同时可在本地和远程会话中运行。This counter measures how long any user input (such as mouse or keyboard usage) stays in the queue before it is picked up by a process, and the counter works in both local and remote sessions.

下图大致表示了从客户端到应用程序的用户输入流。The following image shows a rough representation of user input flow from client to application.

远程桌面 - 用户输入从用户远程桌面客户端流向应用程序

“用户输入延迟”计数器可测量正在排队的输入和被传统消息循环中的应用提取的输入之间的最大增量(在一个时间间隔内),如下面的流程图中所示:The User Input Delay counter measures the max delta (within an interval of time) between the input being queued and when it's picked up by the app in a traditional message loop, as shown in the following flow chart:

远程桌面 - 用户输入延迟性能计数器流

此计数器的一个重要细节是它在可配置的时间间隔内报告最大用户输入延迟。One important detail of this counter is that it reports the maximum user input delay within a configurable interval. 这是输入到达应用程序所需的最长时间,可能会影响重要的可见操作(例如键入)的速度。This is the longest time it takes for an input to reach the application, which can impact the speed of important and visible actions like typing.

例如,在下表中,用户输入延迟在此时间间隔内会被报告为 1000 毫秒。For example, in the following table, the user input delay would be reported as 1,000 ms within this interval. 计数器报告该时间间隔内最慢的用户输入延迟,因为用户对“慢”的感知由体验到的最慢输入时间(最大值),而不是所有总输入的平均速度确定。The counter reports the slowest user input delay in the interval because the user's perception of "slow" is determined by the slowest input time (the maximum) they experience, not the average speed of all total inputs.

数量Number 00 11 22
延迟Delay 16 毫秒16 ms 20 毫秒20 ms 1,000 毫秒1,000 ms

启用和使用新性能计数器Enable and use the new performance counters

若要使用这些新性能计数器,必须首先通过运行以下命令来启用注册表项:To use these new performance counters, you must first enable a registry key by running this command:

reg add "HKLM\System\CurrentControlSet\Control\Terminal Server" /v "EnableLagCounter" /t REG_DWORD /d 0x1 /f

备注

如果使用的是 Windows 10 版本 1809 或更高版本或 Windows Server 2019 或更高版本,则无需启用注册表项。If you're using Windows 10, version 1809 or later or Windows Server 2019 or later, you won't need to enable the registry key.

接下来,重新启动该服务器。Next, restart the server. 然后打开性能监视器并选择加号 (+),如以下屏幕截图中所示。Then, open the Performance Monitor, and select the plus sign (+), as shown in the following screen shot.

远程桌面 - 显示如何添加用户输入延迟性能计数器的屏幕截图

执行该操作后,应看到“添加计数器”对话框,你可以在其中选择“每个进程的用户输入延迟” 或“每个会话的用户输入延迟” 。After doing that, you should see the Add Counters dialog, where you can select User Input Delay per Process or User Input Delay per Session.

远程桌面 - 显示如何添加每个会话的用户输入延迟的屏幕截图

远程桌面 - 显示如何添加每个进程的用户输入延迟的屏幕截图

如果选择“每个进程的用户输入延迟” ,你将看到采用 SessionID:ProcessID <Process Image> 格式的“选定对象的实例” (换而言之,进程)。If you select User Input Delay per Process, you'll see the Instances of the selected object (in other words, the processes) in SessionID:ProcessID <Process Image> format.

例如,如果计算器应用正在会话 ID 1 中运行,你将看到 1:4232 <Calculator.exe>For example, if the Calculator app is running in a Session ID 1, you'll see 1:4232 <Calculator.exe>.

备注

并非包含所有进程。Not all processes are included. 不会看到以系统身份运行的任何进程。You won't see any processes that are running as SYSTEM.

添加该计数器后,就会立即开始报告用户输入延迟。The counter starts reporting user input delay as soon as you add it. 请注意,最大规模默认设置为 100(毫秒)。Note that the maximum scale is set to 100 (ms) by default.

远程桌面 - 性能监视器中每个进程的用户输入延迟的活动示例

接下来,让我们看看“每个会话的用户输入延迟” 。Next, let's look at the User Input Delay per Session. 每个会话 ID 都有实例,并且其计数器显示指定会话中的任何进程的用户输入延迟。There are instances for each session ID, and their counters show the user input delay of any process within the specified session. 此外,有两个名为“最大”(所有会话中的最大用户输入延迟)和“平均”(所有会话中的平均用户输入延迟)的实例。In addition, there are two instances called "Max" (the maximum user input delay across all sessions) and "Average" (the average acorss all sessions).

此表显示了这些实例的可视示例。This table shows a visual example of these instances. (可以通过切换到报表图表类型来获取 Perfmon 中的相同信息。)(You can get the same information in Perfmon by switching to the Report graph type.)

计数器的类型Type of counter 实例名Instance name 报告的延迟(毫秒)Reported delay (ms)
每个进程的用户输入延迟User Input Delay per process 1:4232 <Calculator.exe>1:4232 <Calculator.exe> 200200
每个进程的用户输入延迟User Input Delay per process 2:1000 <Calculator.exe>2:1000 <Calculator.exe> 1616
每个进程的用户输入延迟User Input Delay per process 1:2000 <Calculator.exe>1:2000 <Calculator.exe> 3232
每个会话的用户输入延迟User Input Delay per session 11 200200
每个会话的用户输入延迟User Input Delay per session 22 1616
每个会话的用户输入延迟User Input Delay per session 平均值Average 108108
每个会话的用户输入延迟User Input Delay per session 最大值Max 200200

重载系统中使用的计数器Counters used in an overloaded system

现在,让我们看看在应用性能下降时将看到的报表内容。Now let's look at what you'll see in the report if performance for an app is degraded. 下图显示了用户在 Microsoft Word 中远程工作的读数。The following graph shows readings for users working remotely in Microsoft Word. 在这种情况下,当更多用户登录时,RDSH 服务器性能会随着时间的推移而下降。In this case, the RDSH server performance degrades over time as more users log in.

远程桌面 - 运行 Microsoft Word 的 RDSH 服务器的示例性能图表

下面介绍了如何解读图表的线:Here's how to read the graph's lines:

  • 粉红色的线表示服务器上登录的会话数。The pink line shows the number of sessions signed in on the server.
  • 红色的线表示 CPU 使用率。The red line is the CPU usage.
  • 绿色的线表示所有会话中的最大用户输入延迟。The green line is the maximum user input delay across all sessions.
  • 蓝色的线(在此图表中显示为黑色)表示所有会话中的平均用户输入延迟。The blue line (displayed as black in this graph) represents average user input delay across all sessions.

你会注意到,CPU 峰值与用户输入延迟之间存在关联,即当 CPU 使用率更高时,用户输入延迟就会增加。You'll notice that there's a correlation between CPU spikes and user input delay—as the CPU gets more usage, the user input delay increases. 此外,随着更多的用户添加到系统中, CPU 使用率更接近于 100%,从而导致更频繁的用户输入延迟峰值。Also, as more users get added to the system, CPU usage gets closer to 100%, leading to more frequent user input delay spikes. 虽然此计数器在服务器用完资源的情况下非常有用,但也可以将其用于跟踪与特定应用程序相关的用户输入延迟。While this counter is very useful in cases where the server runs out of resources, you can also use it to track user input delay related to a specific application.

配置选项Configuration Options

使用此性能计数器时需要记住的重要一点是,它在默认情况下以 1000 毫秒的时间间隔报告用户输入延迟。An important thing to remember when using this performance counter is that it reports user input delay on an interval of 1,000 ms by default. 如果将性能计数器示例间隔属性(如以下屏幕截图中所示)设置为其他属性,则报告的值将不正确。If you set the performance counter sample interval property (as shown in the following screenshot) to anything different, the reported value will be incorrect.

远程桌面 - 性能监视器的属性

若要解决此问题,可以设置以下注册表项以匹配你想要使用的间隔(以毫秒为单位)。To fix this, you can set the following registry key to match the interval (in milliseconds) that you want to use. 例如,如果我们将每 x 秒示例更改为 5 秒,则需要将此项设置为 5000 毫秒。For example, if we change Sample every x seconds to 5 seconds, we need to set this key to 5000 ms.

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server]

"LagCounterInterval"=dword:00005000

备注

如果使用的是 Windows 10 版本 1809 或更高版本或 Windows Server 2019 或更高版本,则无需设置 LagCounterInterval 即可修复性能计数器。If you're using Windows 10, version 1809 or later or Windows Server 2019 or later, you don't need to set LagCounterInterval to fix the performance counter.

我们还在同一注册表项下添加了几个可能会有所帮助的项:We've also added a couple of keys you might find helpful under the same registry key:

LagCounterImageNameFirst — 将此项设置为 DWORD 1(默认值 0 或项不存在)。LagCounterImageNameFirst — set this key to DWORD 1 (default value 0 or key does not exist). 这会将计数器名称更改为“映像名称 SessionID:ProcessId”。This changes the counter names to "Image Name SessionID:ProcessId." 例如,“资源管理器 <1:7964>”。For example, "explorer <1:7964>." 如果希望按映像名称进行排序,这将很有用。This is useful if you want to sort by image name.

LagCounterShowUnknown — 将此项设置为 DWORD 1(默认值 0 或项不存在)。LagCounterShowUnknown — set this key to DWORD 1 (default value 0 or key does not exist). 这将显示作为服务或系统运行的任何进程。This shows any processes that are running as services or SYSTEM. 某些进程会显示设置为“?”的会话。Some processes will show up with their session set as "?."

下面是启用两个项时的显示情况:This is what it looks like if you turn both keys on:

远程桌面 - 启用两个项的性能监视器

将新计数器与非 Microsoft 工具结合使用Using the new counters with non-Microsoft tools

监视工具可以通过使用性能计数器来使用此计数器。Monitoring tools can consume this counter by Using Performance Counters.

下载 Windows Server Insider 软件Download Windows Server Insider software

已注册预览体验成员可以直接导航到 Windows Server Insider 预览版下载页以获取最新 Insider 软件下载。Registered Insiders can navigate directly to the Windows Server Insider Preview download page to get the latest Insider software downloads. 若要了解如何注册为预览体验成员,请参阅服务器入门To learn how to register as an Insider, see Getting started with Server.

分享反馈Share your feedback

可以通过反馈中心提交此功能的反馈。You can submit feedback for this feature through the Feedback Hub. 选择“应用”>“所有其他应用” ,并在帖子标题中包括“RDS 性能计数器 - 性能监视器”。Select Apps > All other apps and include "RDS performance counters—performance monitor" in your post's title.

若要了解常规功能想法,请访问 RDS UserVoice 页面For general feature ideas, visit the RDS UserVoice page.