--- trunk/vz-optimize.pl 2007/01/31 21:12:47 14 +++ trunk/vz-optimize.pl 2007/02/01 10:40:05 15 @@ -4,6 +4,18 @@ use Data::Dump qw/dump/; +my $watch_current = 'held'; +my $watch_max = 'limit'; + +# tune optimizer +my $increase_over = 0.95; # 95% of resource $watch used +my $increase_limit = 1.1; +my $increase_barrier = 1.2; + +($watch_current,$watch_max) = ('maxheld','barrier'); + +my $debug = 0; + my $proc='/proc/user_beancounters'; $proc='./user_beancounters' if (! -e $proc); @@ -14,7 +26,7 @@ my $d; -my $increase_over = 0.95; # 95% of resource limit used +warn "increasing $proc if $watch_current > $watch_max * $increase_over\n"; while(<$bc>) { chomp; @@ -41,16 +53,16 @@ if ($r->{failcnt} > 0) { - if ( ($r->{held} / $r->{limit}) > $increase_over ) { - my $new_limit = int($r->{limit} * 1.1); - my $new_barr = int($r->{limit} * 1.2); - warn "# $vmid $res $r->{limit} -> $new_limit:$new_barr\n"; + if ( ($r->{ $watch_current } / $r->{ $watch_max }) > $increase_over ) { + my $new_limit = int( $r->{ $watch_max } * $increase_limit ); + my $new_barr = int( $r->{ $watch_max } * $increase_barrier ); + warn "# $vmid $res $r->{ $watch_max } -> $new_limit:$new_barr\n"; my $cmd = "vzctl set $vmid --${res} $new_limit:$new_barr --save"; warn $cmd,$/; - system $cmd; + system $cmd if (! $debug); } else { warn sprintf("%s/%s failed, but not used %d%% [%d/%d %d%%]\n", - $vmid, $res, $increase_over * 100, $r->{held}, $r->{limit}, ($r->{held}/$r->{limit})*100 + $vmid, $res, $increase_over * 100, $r->{ $watch_current }, $r->{ $watch_max }, ($r->{ $watch_current }/$r->{ $watch_max })*100 ); }