0

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. 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. This program can run on a variety hardware configurations( e.g processor speed, number of cores), so 50% limit can be too harsh or soft for certain configurations.

Is there any good way to include different parameters of CPU configuration e.g cores, speed; which can dynamically come up with a threshold number based on the hardware configuration?

scanty
  • 1
  • 1

1 Answers1

0

My suggestions:

  1. Run as many threads as CPUs in the system.
  2. Set the priority of each thread to an idle (lowest)
  3. In the thread main loop do a smallest sleep possible, i.e. usleep(1)
Andriy Berestovskyy
  • 8,059
  • 3
  • 17
  • 33
  • In this case count of threads is not controlled, but determined by the running tasks. The problem is more towards scheduling an optimal number of tasks which makes sure we are maximizing resource utilization and keeping the application responsive at the same time. What I am looking for is a way to normalize the processing power number such that threshold scales up/down according to the capability of the processor. – scanty May 17 '17 at 12:42
  • That is why it is IMO better to have those threads always running, but with the lowest priority and with sleeps, so basically scheduler will do this for you... – Andriy Berestovskyy May 17 '17 at 12:55
  • But sure, it is up to you ;) – Andriy Berestovskyy May 17 '17 at 12:55