Windows 11 中通过编程方式启用“Efficiency Mode” 对服务的影响是什么?

huangapple go评论106阅读模式
英文:

Effects of programmatically enabling `Efficiency Mode` for services in Windows 11?

问题

假设有一个在白天非常繁忙但通常在晚上空闲的服务。

目前任务管理器显示未启用效率模式

Windows 11 中通过编程方式启用“Efficiency Mode” 对服务的影响是什么?

然而,应用下面的代码更改后,任务管理器显示效率模式已启用

Windows 11 中通过编程方式启用“Efficiency Mode” 对服务的影响是什么?

通过以下方法实现了这种模式

  • 首先,效率模式降低了后台任务的进程优先级,以便Windows不分配重要资源给这些应用程序。
  • 其次,它部署了一种称为EcoQoS的东西,这是一种降低高效任务时钟速度的服务质量包。

要在任务管理器中显示效率模式,至少需要这两个(通过反复尝试):

  1. 将进程优先级类设置为IDLE_PRIORITY_CLASS
  2. 使用PROCESS_POWER_THROTTLING_EXECUTION_SPEED节流CPU功率
#include <windows.h>

// 将进程优先级设置为IDLE_PRIORITY_CLASS。
void set_process_priority()
{
    SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS);
}

// 启用EcoQos以降低时钟速度。
void enable_ecoqos()
{
    PROCESS_POWER_THROTTLING_STATE PowerThrottling = { 0 };
    PowerThrottling.Version = PROCESS_POWER_THROTTLING_CURRENT_VERSION;
    PowerThrottling.ControlMask = PROCESS_POWER_THROTTLING_EXECUTION_SPEED;
    PowerThrottling.StateMask = PROCESS_POWER_THROTTLING_EXECUTION_SPEED;

    SetProcessInformation(GetCurrentProcess(), ProcessPowerThrottling, &PowerThrottling, sizeof(PowerThrottling));
}

int main(int argc, char* argv[])
{
    set_process_priority();
    enable_ecoqos();

    // 现在进程正在运行效率模式...

    return 0;
}

问题

在白天服务非常繁忙时启用效率模式是否会导致性能下降?(试图降低CPU/内存使用成本,使其更加绿色软件友好)。

是否有其他效率选项可以启用以改善整体的效率模式

英文:

Suppose there's a service that's extremely busy during the day but generally idle at night.

Currently Task Manager shows Efficiency mode not enabled

Windows 11 中通过编程方式启用“Efficiency Mode” 对服务的影响是什么?

However, applying the code changes below, Task Manager shows Efficiency mode enabled

Windows 11 中通过编程方式启用“Efficiency Mode” 对服务的影响是什么?

It achieves this mode by applying these methods

  • First, the Efficiency mode lowers the process priority of background
    tasks so that Windows does not allocate important resources to these
    apps.
  • Second, it deploys something called EcoQoS, which is a Quality of
    Service package that reduces the clock speed for efficient tasks.

To get the Efficiency mode to appear in the Task Manager, at a minimum these two are required (through trial and error):

  1. Set process priority class to IDLE_PRIORITY_CLASS
  2. Throttle CPU power with PROCESS_POWER_THROTTLING_EXECUTION_SPEED

<br>

#include &lt;windows.h&gt;

// Sets the process priority to IDLE_PRIORITY_CLASS.
void set_process_priority()
{
    SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS);
}

// Enables EcoQos to reduce the clock speed.
void enable_ecoqos()
{
    PROCESS_POWER_THROTTLING_STATE PowerThrottling = { 0 };
    PowerThrottling.Version = PROCESS_POWER_THROTTLING_CURRENT_VERSION;
    PowerThrottling.ControlMask = PROCESS_POWER_THROTTLING_EXECUTION_SPEED;
    PowerThrottling.StateMask = PROCESS_POWER_THROTTLING_EXECUTION_SPEED;

    SetProcessInformation(GetCurrentProcess(), ProcessPowerThrottling, &amp;PowerThrottling, sizeof(PowerThrottling));
}

int main(int argc, char* argv[])
{
    set_process_priority();
    enable_ecoqos();

    // Process is now running in Efficiency mode...

    return 0;
}

Question

Will enabling Efficiency mode cause degraded performance issues during the day when the service is very busy? (Trying to lower the costs of CPU/Memory usage and make it more Green Software friendly).

Are there other efficiency options that could be enabled to improve the overall Efficiency mode?

答案1

得分: 2

因为效率模式会降低分配给服务的资源并降低其相对于其他运行服务的优先级,将一个进程切换到效率模式可能会降低其整体性能。

是否重要取决于许多因素。如果服务设计良好,它仍然应该能够正常运行。操作系统通常会优先考虑高需求的服务。

减少资源的目的不是为了提高性能(对于具有更高优先级的进程来说),而是为了保持系统的响应性。如果一个后台进程大部分时间都处于空闲状态,那么消耗大量资源就没有太多意义。

我曾经在一家公司工作,他们有一台服务器每秒轮询 SQL Server 终端点十次。你可以想象,如果服务器大部分时间都处于空闲状态,而大部分工作都在夜间进行,那么这是相当浪费的。我修改了代码,使其在连续六秒的空闲后将轮询间隔降低到每秒一次。在另外一分钟的空闲后,将轮询间隔降低到每分钟一次。如果一次轮询产生了活动请求,间隔就会恢复到每秒十次。

这样做的效果是消除了大部分的浪费活动,同时在繁忙时期保持了服务器的响应性。

英文:

Because Efficiency Mode reduces the resources allocated to a service and reduces its priority relative to other running services, switching a process to Efficiency Mode would likely reduce its overall performance.

Whether that matters or not depends on many factors. If the service is well-designed, it should still perform adequately, however. The operating system typically defers to services that are in high-demand.

The point of reducing resources is not to achieve performance gains (to those processes having higher priorities); it is to keep the system responsive. It doesn't make much sense for a background process to consume large amounts of resources if it spends most of its time idle.

I once worked in a company that had a server which polled a SQL Server endpoint ten times per second. As you can imagine, this is quite a waste if the server sits idle most of the day and does the bulk of its work at night. I changed the code so that after six seconds of inactivity, it reduced the polling interval to once per second. After another minute of inactivity, it reduced the polling to once per minute. If a poll produced a request for activity, the interval went back up to 10 per second.

This had the effect of eliminating most of the wasteful activity, while still making the server responsive during its busy times.

huangapple
  • 本文由 发表于 2023年1月9日 00:30:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/75049477.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定