问题
Hi am developing a load balancing algorithm in java. In my system there will be one mater node and list of slave nodes, Where the master node will distribute the incoming request to one of its slave node. I want to find the C.P.U load (percentage of C.P.U utilized) in each of the slave nodes. So that the master node can effectively distribute the request to one of its least loaded slave node. Can any one please suggest me how can we find it.
The getSystemLoadAverage() method in JMX
can be used to find the cpu load of the current system. Is it possible to use the same method to find the load in slave too.. If possible please suggest me how can we find it. If not possible please suggest me some other way to do the same. I will be more thankful if some one provide right answer for this.
回答1:
If you have an mbean on the slaves you can monitor memory used, CPU etc. I suggest you add some external monitoring app which you control through the mbean and collect the data through the mbean and send it to the master.
You should not assume that if a CPU is 10% utilized, it can accept more jobs. What if memory is 90%, there could be other things as well.
EDIT 1:
Links to mbeans:
http://docs.oracle.com/javase/tutorial/jmx/mbeans/standard.html
Scroll down:
http://java.sun.com/developer/technicalArticles/J2SE/jmx.html
回答2:
Check out Sigar: http://www.hyperic.com/products/sigar
It has language and platform bindings for virtually everything. I've used Sigar many times. It's simple, reliable and just works. And you get a lot more platform stats than just CPU load, which can be handy depending on what more info you might need.
来源:https://stackoverflow.com/questions/9219237/how-to-find-the-c-p-u-load-percentage-of-c-p-u-utilization-in-the-slave-node