Skip to main content
3 of 3
bullets
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.

Some alternative approaches I can think of:

  • 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.

  • Can you model the calculations as map-reduce problems (or otherwise separate input data from code)? Then you could calculate how hard a problem is based on input data 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.

  • 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 calculation is not trivial?

Martin Wickman
  • 13.4k
  • 3
  • 33
  • 66