/[vz-tools]/trunk/vz-optimize.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/vz-optimize.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 14 by dpavlin, Wed Jan 31 21:12:47 2007 UTC revision 15 by dpavlin, Thu Feb 1 10:40:05 2007 UTC
# Line 4  use strict; Line 4  use strict;
4    
5  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
6    
7    my $watch_current = 'held';
8    my $watch_max = 'limit';
9    
10    # tune optimizer
11    my $increase_over = 0.95;       # 95% of resource $watch used
12    my $increase_limit = 1.1;
13    my $increase_barrier = 1.2;
14    
15    ($watch_current,$watch_max) = ('maxheld','barrier');
16    
17    my $debug = 0;
18    
19  my $proc='/proc/user_beancounters';  my $proc='/proc/user_beancounters';
20  $proc='./user_beancounters' if (! -e $proc);  $proc='./user_beancounters' if (! -e $proc);
21    
# Line 14  my $vmid; Line 26  my $vmid;
26    
27  my $d;  my $d;
28    
29  my $increase_over = 0.95;       # 95% of resource limit used  warn "increasing $proc if $watch_current > $watch_max * $increase_over\n";
30    
31  while(<$bc>) {  while(<$bc>) {
32          chomp;          chomp;
# Line 41  while(<$bc>) { Line 53  while(<$bc>) {
53    
54    
55          if ($r->{failcnt} > 0) {          if ($r->{failcnt} > 0) {
56                  if ( ($r->{held} / $r->{limit}) > $increase_over ) {                  if ( ($r->{ $watch_current } / $r->{ $watch_max }) > $increase_over ) {
57                          my $new_limit = int($r->{limit} * 1.1);                          my $new_limit = int( $r->{ $watch_max } * $increase_limit );
58                          my $new_barr = int($r->{limit} * 1.2);                          my $new_barr = int( $r->{ $watch_max } * $increase_barrier );
59                          warn "# $vmid $res $r->{limit} -> $new_limit:$new_barr\n";                          warn "# $vmid $res $r->{ $watch_max } -> $new_limit:$new_barr\n";
60                          my $cmd = "vzctl set $vmid --${res} $new_limit:$new_barr --save";                          my $cmd = "vzctl set $vmid --${res} $new_limit:$new_barr --save";
61                          warn $cmd,$/;                          warn $cmd,$/;
62                          system $cmd;                          system $cmd if (! $debug);
63                  } else {                  } else {
64                          warn sprintf("%s/%s failed, but not used %d%% [%d/%d %d%%]\n",                          warn sprintf("%s/%s failed, but not used %d%% [%d/%d %d%%]\n",
65                                  $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
66                          );                          );
67                  }                  }
68    

Legend:
Removed from v.14  
changed lines
  Added in v.15

  ViewVC Help
Powered by ViewVC 1.1.26