Skip to main content
2 of 3
added 169 characters in body
Martin Wickman
  • 13.4k
  • 3
  • 33
  • 66

Not to my knowledge, it seems extremely hard to get right. Even if you could do it, you still have to consider system load, number of cores, other os activities etc.

A simplistic idea: would it be possible to start the calculation and simply wait until a certain time has passed and then move it to a separate thread, once you realize this calcuation is not trivial?

Have you considered a pool of threads or a dispatch queue? At least that allows you avoid some issues with context switching etc and you can balance the system as a whole dynamically based on the total amount of usage and jobs.

Are the jobs arbitrary blocks of code or can you model them as map-reduce problems or some other way that separates input data from code? That way you could calculate how hard a problem is based on data input size and throughput for each item. After a bunch of samples you should be able to determine how much time it should take in total for the calculation to complete, and thus decide to run it locally or distributed.

Martin Wickman
  • 13.4k
  • 3
  • 33
  • 66