评估 Windows 系统的负载
我用 php 编写了一个图像处理脚本,它作为 cron 计划任务运行(在 OSX 中)。 为了避免系统过载,该脚本会检查系统负载(使用“正常运行时间”),并且仅在负载低于预定义阈值时运行。
我现在已将其移植到 Windows (2003 Server),并正在寻找类似的命令行函数来将系统负载报告为整数或浮点数。
I've written an image processing script in php which is run as a cron scheduled task (in OSX). To avoid overloading the system, the script checks the system load (using 'uptime') and only runs when load is below a predefined threshold.
I've now ported this over to Windows (2003 Server) and am looking for a similar command line function to report system load as an integer or float.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
不要使用负载...
在这种情况下,系统负载不是一个好的指标。 在 Unix 上,它本质上告诉您,目前有多少进程已准备好并等待执行。 但是,由于进程可能需要等待的原因有很多,因此即使系统上的“负载”很高,您的脚本实际上也可能能够运行而不会影响另一个进程的任何性能。
...使用nice
您应该在Unix 上使用
nice(1)
以及在Windows 上的等效项(“进程优先级”?),以便操作系统可以决定何时运行您的脚本!如果您将脚本的优先级设置为绝对最低的优先级,那么只有当此时没有其他事情可做时,它才会由调度程序执行。
也许您必须实现某种机制来防止同时运行多个脚本实例,以防执行时间比调用之间的间隔时间更长。
Don't use load...
The system load is not a good indicator in this case. On Unix it essentially tells you, how many processes are ready and waiting to be executed at the moment. But since there are numerous reasons for why a process might have to wait, your script may actually be able to run without costing another process any performance, even if the "load" on the system is high.
... use nice
You should use
nice(1)
on Unix and the equivalent on Windows ("Process Priority"?), so the OS can decide, when to run your script!If you set the priority of your script to the absolute lowest possible priority then it will only be executed by the scheduler when there is nothing else to do at the moment.
Probably you will have to implement some kind of mechanism to prevent more than one instance of your script to be run at the same time, in case it takes longer to execute than the interval between to invocations lasts.
您可以在 Windows 命令行中尝试此操作。 这在 XP 中有效,还可以获得很多其他信息。
无线麦克风CPU
You can try this at a windows command line. This works in XP, get a lot of other info too.
wmic CPU
您可以使用名为 pv 的命令行实用程序来显示进程名称和 CPU%使用此命令行在特定时间段(默认为 500 毫秒)内的使用情况:
有使用
-?
开关的帮助来描述可用参数。与 OSX/linux 上的正常运行时间相比,它需要更多的工作,因为您必须对第一列中的数字进行求和(或省略进程名称并简单地对每行输出的值进行求和)才能获得总数(以 % 为单位) ) CPU使用率。
好处是,只需多做一点工作,您就可以获得执行进程正在使用的具体 CPU 量,而不是总体系统 CPU 消耗。
You can use a command-line utility called pv to display the process name and CPU% usage over a specific time period (defaults to 500ms) using this command line:
There is help using the
-?
switch that describes the available parameters.It will require a little more work than uptime on OSX/linux, since you would have to total the numbers from the first column (or omit the process name and simply total the value form each line of output) to get the total (in %) CPU usage.
The up side is that with a little more work, you could get the specific amount of CPU that your executing process is using, rather than overall system CPU consumption.
WMI 对 Windows 中的几乎所有内容进行基准测试,包括系统负载。
我发现一个关于它的帖子。
WMI benchmarks pretty much everything in Windows, including system load.
I found a thread about it.
只需使用标准 win32 api (GTC)
Just use standard win32 apis (GTC)