/[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

Annotation of /trunk/vz-optimize.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 15 - (hide annotations)
Thu Feb 1 10:40:05 2007 UTC (16 years ago) by dpavlin
File MIME type: text/plain
File size: 1608 byte(s)
extract parametars in variables (pending options addition)

1 dpavlin 1 #!/usr/bin/perl -w
2    
3     use strict;
4    
5     use Data::Dump qw/dump/;
6    
7 dpavlin 15 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 dpavlin 1 my $proc='/proc/user_beancounters';
20     $proc='./user_beancounters' if (! -e $proc);
21    
22     open(my $bc, '<', $proc) || die "can't open $proc: $!";
23    
24     my @cols;
25     my $vmid;
26    
27     my $d;
28    
29 dpavlin 15 warn "increasing $proc if $watch_current > $watch_max * $increase_over\n";
30 dpavlin 3
31 dpavlin 1 while(<$bc>) {
32     chomp;
33     next if (/^Version/);
34    
35     $vmid = $1 if (s/^\s+(\d+):\s+//);
36     s/^\s+//;
37    
38     my @d = split(/\s+/,$_);
39    
40     if ($#d == 6 && $d[0] =~ m/^\w+$/) {
41     @cols = splice(@d,1);
42     # warn "## found cols: ", dump(@cols), "\n";
43     next;
44     }
45    
46     my $res = $d[0];
47    
48     foreach my $i ( 1 .. $#cols ) {
49     $d->{ $vmid }->{ $res }->{ $cols[$i] } = $d[$i];
50     }
51    
52     my $r = $d->{ $vmid }->{ $res };
53    
54    
55     if ($r->{failcnt} > 0) {
56 dpavlin 15 if ( ($r->{ $watch_current } / $r->{ $watch_max }) > $increase_over ) {
57     my $new_limit = int( $r->{ $watch_max } * $increase_limit );
58     my $new_barr = int( $r->{ $watch_max } * $increase_barrier );
59     warn "# $vmid $res $r->{ $watch_max } -> $new_limit:$new_barr\n";
60 dpavlin 14 my $cmd = "vzctl set $vmid --${res} $new_limit:$new_barr --save";
61     warn $cmd,$/;
62 dpavlin 15 system $cmd if (! $debug);
63 dpavlin 1 } else {
64 dpavlin 3 warn sprintf("%s/%s failed, but not used %d%% [%d/%d %d%%]\n",
65 dpavlin 15 $vmid, $res, $increase_over * 100, $r->{ $watch_current }, $r->{ $watch_max }, ($r->{ $watch_current }/$r->{ $watch_max })*100
66 dpavlin 3 );
67 dpavlin 1 }
68    
69     }
70     }
71     close($bc);
72    
73     #print dump($d);

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26