简体   繁体   English

检测不同机器上的CPU负载

[英]Detecting CPU load on different machines

I am trying to create a background task scheduler for my process, which needs to schedule the tasks(compute intensive) parallelly while maintaining the responsiveness of the UI. 我正在尝试为我的流程创建一个后台任务计划程序,该程序需要并行计划任务(计算密集型),同时保持UI的响应能力。 Currently, I am using CPU usage(percentage) to against a threshold (~50%) for the scheduler to start a new task, and it sort of works fine. 目前,我正在使用CPU使用率(百分比)使调度程序开始执行新任务的阈值(〜50%),并且可以正常工作。 This program can run on a variety hardware configurations( eg processor speed, number of cores), so 50% limit can be too harsh or soft for certain configurations. 该程序可以在各种硬件配置(例如处理器速度,内核数)上运行,因此对于某些配置,50%的限制可能太苛刻或太软。

Is there any good way to include different parameters of CPU configuration eg cores, speed; 有没有什么好办法可以包含不同的CPU配置参数,例如内核,速度; which can dynamically come up with a threshold number based on the hardware configuration? 哪些可以根据硬件配置动态提出阈值?

My suggestions: 我的建议:

  1. Run as many threads as CPUs in the system. 运行与系统中CPU一样多的线程。
  2. Set the priority of each thread to an idle (lowest) 将每个线程的优先级设置为空闲(最低)
  3. In the thread main loop do a smallest sleep possible, ie usleep(1) 在线程主循环中执行最小的睡眠,即usleep(1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM