1: Two years ago, when a colleague had root access to our
2: lab's SUN 4500s (8 processors each, each running at 500mhz),
3: we decided that all those spare processor cycles were
4: going to waste. With his knowledge of UNIX calls and
5: my affinity for perl, we came up with a SETI runner which
6: fired up new instances when the system was idle, and
7: killed instances when the system load went up.
8:
9:
10: my $uptime = "uptime"; # or whatever it's called...
11:
12: my $setiRoot = '/usr/bin/seti';
13: my $setiBinary = 'setiathome';
14: my $setiFlags = '';
15: my $setiLog = 'seti.log';
16:
17: my $napTime = 2;
18:
19: my $maxInstances = 8; # maximum number of SETI instances
20: my $minInstances = 0; # minimum number of SETI instances
21: my $lowThreshold = 8.00; # start SETI
22: my $hiThreshold = 9.00; # stop SETI
23:
24: my @setiPids; # pid array
25:
26: while(1)
27: {
28: sleep( $napTime );
29:
30: my $uptime = `$uptime`;
31:
32: $uptime = $1 if $uptime =~ /load average: (\d+\.\d\d)/;
33:
34: print STDERR "load average: $uptime\n";
35:
36: #
37: # if the uptime is below a certain load,
38: # then fire up a new SETI instance.
39: #
40: &startSETI
41: if ( ($uptime < $lowThreshold) && (@seti < $maxInstances) );
42:
43: #
44: # if the uptime is above a certain load,
45: # then kill a SETI instance.
46: #
47: &stopSETI
48: if ( ($uptime > $hiThreshold) && (@seti > $minInstances) );
49: }
50:
51: #
52: # Organize our list of PIDs
53: #
54: sub startSETI
55: {
56: print STDERR "Firing up a SETI...\n";
57: print STDERR "We have ", scalar( @setiPids ), " PIDs:\n";
58: print STDERR join( " ", @setiPids ), "\n";
59: # list all processes
60: my $number = scalar( @setiPids );
61:
62: chdir( "$setiRoot/seti$number" );
63:
64: print STDERR "Working directory: $setiRoot/seti$number\n";
65:
66: push( @setiPids, `$setiBinary $setiFlags > $setiLog` );
67: }
68:
69: #
70: # Quick and dirty killer
71: #
72: sub stopSETI
73: {
74: print STDERR "Shutting down a SETI...\n";
75:
76: kill 9, pop @setiPids;
77: }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl ran SETI@Home for us.
by qslack (Scribe) on Nov 27, 2001 at 06:01 UTC | |
by grinder (Bishop) on Nov 27, 2001 at 19:19 UTC | |
by ar0n (Priest) on Nov 27, 2001 at 19:36 UTC | |
by rje (Deacon) on Nov 27, 2001 at 22:04 UTC | |
|
Re: Perl ran SETI@Home for us.
by Fatty Lumpkin (Acolyte) on Dec 12, 2001 at 02:02 UTC | |
by rje (Deacon) on Dec 12, 2001 at 02:16 UTC |