Menu

Tree [r10] /
 History

HTTPS access


File Date Author Commit
 CHANGELOG 2012-04-20 kangshiyin [r10] change the invoking order of ps and top,
 README 2012-04-19 kangshiyin [r7] put changelog to a separate file
 cpubalance.conf 2012-04-15 kangshiyin [r4] bug fixed: renice thread in CentOS
 cpubalance.pl 2012-04-20 kangshiyin [r10] change the invoking order of ps and top,

Read Me

CPU Balance is a Perl script to balance the CPU usage among users. 
It will allocate CPU resource to each user equally only by the command renice, 
no matter how many processes/threads a user runs. 



##### How to use ##########################################

Your can run CPU Balance by adding the following line to /etc/crontab,
which makes CPU Balance run every 10 seconds.

* * * * * root  for n in 1 2 3 4 5 6; do /usr/bin/perl /PATH/TO/cpubalance.pl /PATH/TO/cpubalance.conf >/dev/null 2>&1 & sleep 10; done &


####### some more detail about CPU Balance ##############################

 Basic Renice Goal:
 1. User-based balance: every user get the same cpu percent no matter how
    many proc/threads he/she runs;
 2. all the jobs of one user has the same NI;
 3. NI of all jobs tend to move as large as possible when balanced;
 4. No sudden change on NI. max change of NI of a proc <= 2. Only part of
    the users ( 1 is enough but may take long time before balanced ) will
    be changed in a renice cycle.

 Advanced Features:
 1. gid/uid/cmd based renicable filter
 2. gid/uid based weighted cpu division: priority & punished user support

 Renice Stratergy:
 1. choose renicable proc/threads;
 2. determine target cpu for each user, determine renice direction;
 3. choose 1 user to renice: users move towards the max NI is prefered;
    among prefered users, the one whose (cpu / target) is most far from 1 is
    the final winner.
 4. renice the processes by proc group. move all NI by 1 to the pre-determined
    direction, then, if processes have different NIs, make the rear ones move
    another step to catch up with the front ones.




##############################################################
The following is some more detail about the script.

The basic idea of the renice strategy is to decrease the distance between
current cpu usage of a user and the average cpu usage of all the active users.

In each renice cycle, it picks part of the active users whose cpu usage is most far from the average,
and then changes the NI by 1 to reduce the distance.

The renicable uid/gid list can be set in the conf file. Currently it is [100,65535] for both uid and gid.
A special uid/gid list can also be set to make some users can share more/less cpu than ordinary users.