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