Q:

improve application performance and intelligence

I have a question which is related to application performance and intelligence.
I have created a window service, if I run it on a 3 different configuration machines. I want it to utilize appropriate resources of machine (CPU and memory).
Say Machine 1(M1) have single core with 1 GB ram.
Machine2 (M2) has two cores with 2 GB ram.
Machine3 (M3) has 4 cores with 4 GB ram.
Now when my service runs on it, it should utilize proper resource. Like if cpu use of machine is 1% it should go on user upto 50% or more. If it’s already 50% use only 30%. So do ram. But never cross a limit like 90% or something.
Basically I wrote a multithreaded service which right now don’t care about machine resources and keep on utilizing it. I want to include this intelligence in it.
Please help me out with your ideas.
Thanks

A:

As Archeg said, based on the number of processors, you can increase the thread count. But increasing the number of threads based on CPU activity is the wrong way to go about it.
Look at it this way - the CPU scheduler allocates time-slots at a millisecond granularity. If the load on the system from other processes is low, it will give your process more time. Period. If there are lots of processes, you will get time-slots less often. You shouldn't thrash it with more threads than necessary.
What you need to do is decide what you want to do. Is the service time-sensitive? If so, then in a heavily-loaded system, you have less CPU time to operate with, and in an idle system, you can use more CPU time within the same, say, second. Beware: If your service does I/O, maybe your service itself throttles how much CPU it can use.
With RAM, you could do something like, given how much free RAM the system has, switch algorithms to one that uses less processing or processes faster, but needs more memory (and vice-versa).
The point is that there's no 'service-independent' way to do this kind of intelligent scaling, besides better schedulers (which is something a lot of smart people have been looking at for many many years). You can however write services that are aware of current system constraints and change behavior accordingly.

