Reputation: 823
I have an application that distributes work to multiple threads. Sometimes one thread takes too much CPU load and all other threads suffer of that. What can I do to manage threads in such way that if one thread is going up with using CPU then just pause it, or slice it down to make all threads load to be more or less even.
Updated My tasks are independent. Not sure if is possible to add performance counters for each thread and measure load. If thread goes out of limits than pause it until later time.
Updated Problem with using TPL load balancing is that my threads are STA. Kind of solution is to create home brewed load balancing following well known algorithms like "round-robin load balancing".
Upvotes: 0
Views: 98
Reputation: 161791
You say that you distribute work to multiple threads. So, it's up to you to break down and distribute the work properly. You will need to understand the performance of your code well enough tht you can look at the workload and decide how much resources that workload will require. You can then split up the workload so that each unit of work is more or less the same in terms of resources.
I don't think you're going to find a complete magical solution. Something like the Task Parallel Library i .NET 4.0 and above can help, but it's not a silver bullet.
Upvotes: 2