[TLC] - some scripts for linux

Status
Not open for further replies.

JessF

Ars Scholae Palatinae
737
In the "race to TLC #250" thread Hagabard wanted to see my seti at linux scripts. Others might be interested, so here they are in a seperate thread.

The scripts are based on being in ~/seti with sub-dirs for each "cached" wu. These dirs must be made manually and have seti installed. The executeable "setiathome" could either be copied to each dir or it could be a symlink from each dir to make it easier to upgrade. "user_info.sah" and others should also be copied to each dir.

I don't remember which .sah files should be copied, but others should be able to help, or you could experiment. From a dir where you have "logged in" to seti, you could copy everything and just delete the "work_unit.sah".

~/seti/run
The file that runs seti "forever" - put it in a startup-script or make it a cronjob (or whatever)

code:<HR>
Code:
#!/bin/tcsh<P>touch ~/seti/seti.log<P>while (1)
  foreach wu (1 2 3 4 5 6 7 8)
    cd ~/seti/${wu}
    echo ""
    if (-e work_unit.sah) then
        echo -n "WU ${wu} start `date`"
        echo "WU ${wu} start `date`" >> ../seti.log
        ./setiathome -nice 8 -stop_after_process >> ../seti.log
    else
        echo -n "WU ${wu} missing `date`"
        echo "WU ${wu} missing `date`" >> ../seti.log
        sleep 300
    endif
  end # foreach
end # while

It outputs to both ~/seti/seti.log and to stdout - I like have a window showing what it does. You could remove one or both from the script. The "sleep 300" is in case no WU's are ready, so it doesn't loop too fast - another personal preference.

~/seti/xfer
The script that up-/down-loads WU's. Either run it manually when your dial-up connection is up, or set it to run 1 or more times each day if your machine is "allways-on".

code:<HR>
Code:
#!/bin/tcsh
foreach wu (1 2 3 4 5 6 7 8)
  if (-e ~/seti/${wu}/work_unit.sah) then
      echo WU ${wu} ready
  else
      echo WU ${wu} missing
      cd ~/seti/${wu}
      ./setiathome -stop_after_xfer
  endif
end # for

You can put your proxy-settings in the "./setiathome ..." line

~/seti/list
Shows the status of each WU

code:<HR>
Code:
#!/bin/tcsh<P>foreach wu (1 2 3 4 5 6 7 8)
  echo ""
  echo -n "WU ${wu}: "
  if (-e ~/seti/$wu/work_unit.sah) then
      if (-s ~/seti/${wu}/state.sah) then
          echo -n `grep prog ~/seti/${wu}/state.sah | cut -c 8-9`
      else
          echo -n ready
      endif
  else
      echo -n done
  endif
end # foreach

~/seti/listrep
Repeats list. Nice for a little status window

code:<HR>
Code:
#!/bin/tcsh
while (1)
    clear
    echo -n `date`
    ~/seti/list<P>    sleep 10m
end

-------------

This should work on any other *NIX. They are based on tcsh - my default shell (it was the default shell on the first UNIX system I was a user on - it has stuck). You might have to adjust the path to tcsh - it isn't in /bin on the HP-UX I can login on.

I use 8 dirs named 1, 2, 3, 4, 5, 6, 7 and 8, but you can use any number of dirs with whatever names you want if you just edit the "foreach ..." lines in the scripts.

I've edited the scripts a little for display here - most of the output-text was in Danish. You might want to edit the "date" commands to show a shorter date-format.

In the output to stdout I use "echo -n" a lot - It doesn't leave a blank line under the text, so a status window can be one line smaller.
 
I have found it better to dispense with loops altogether. I simple do the straightforward thing:

code:<HR>
Code:
cd ~/seti/dir1
../setiathome -parms -stop_after_process
cd ../dir2
../setiathome -parms -stop_after_process
.... (etc)

I then run a by-hand transmit script now and then:

code:<HR>
Code:
cd ~/seti/dir1
../setiathome -parms -stop_after_xmit
cd ../dir2
../setiathome -parms -stop_after_xmit

I kick the first script off with a suitable cron entry, roughly synchronized with the necessary frequency of execution. In particular, I try and have two running jobs at all times, each in a different portion of the cache. Since Linux keeps track of execution on a per-job basis, there's no real penalty to the average (if you care about that) and much practical benefit. This way, if one job fails (or "waits an hour and tries again"), the other continues to run. With the right cache size, this works out very well.

If you do loops, the "sleep 300" is a bit more than a personal preference -- if SETI has an outage, it keeps you from being a bad guy and slamming the server (something they call out explicitly on the web site). It also keeps your log ( the >> seti.log stuff) from filling up with garbage during those same intervals. A five minute sleep is, like the task switches for multiple SETI jobs, an insignificant loss to your WU rate.

The reason I ulitimately dispensed with looping methods (I tried them) is that during an outage, you are actually better off letting the old job die and crond restart the new. The sleep trick "should be" enough and maybe some will find it acceptable, but during an outage of any length, I found the things it did to one's log (even at a once-per-five-minute rate) was basically a pain in the rear if the cache ran dry.

If you got the right-sized cache, the nonlooping scripts work just fine (you don't run dry) and the restart will happen before you run out.

If the cache expires, and you run dry, then restarting by hand (or waiting for the next crond point) works just as well if not better, in practice, than a nagy script that tries to download every five minutes.

Moreover, during an actual outage long enough to run you dry, it may hurt SETI's recovery to have thousands of machines beating on it with relatively short retries measured in fives of minutes (they recommend a much larger interval betwee retries right on the download page last I looked).


PS, if you are continuously connected, it is sufficient to have merely two directories and two jobs, kicked off at alterntive times on a daily basis by crond. Caching is, in fact, overrated.

The majority of outages are such that two WUs per CPU is plenty, in practice, to deal with 99% of the outages. What people remember is the one or two one day duration outages a year and they overcompensate to capture that last one percent. For 3.03, two jobs per CPU is still plenty for most machines and most outages. If that's not enough, the scripts above still work. The transmit scripts work a bit better being kicked off by hand.

[This message was edited by Larry Loen on April 23, 2001 at 09:37.]
 

Hagabard

Ars Scholae Palatinae
993
First, there are going to be two seprate scripts. I'm still working on these, but here is what I think will work the way I want it too. (I'm probbably actually implementing this later on tonight.)

These are in bash, because it's what I know. :) Korn, Z, and possibly Ash shells might work too.

Script #1 - xferwu (add .sh to taste)
code:<HR>
Code:
#!/bin/sh
SETIDIR=/home/you/seti
cd $SETIDIR
for i in [1 2 3 4 5 6 7 8 9]; do
  cd $SETIDIR/$i
  ../setiathome -parms -stop_after_xmit
done

Very short. Will download/upload 9 WU in this case. Very simple. Runs out of cron job. (More on this later.) Like I said, it isn't terribly sexy yet. I'm going to 'steal' some ideas here to make it better.

Script #2 - crunchwu (again, add .sh to taste)
code:<HR>
Code:
#!/bin/sh
SETIDIR=/home/you/seti
cd $SETIDIR
until [ "$var1" = end ]; do
 for i in [1 2 3 4 5 6 7 8 9]; do
  cd $SETIDIR/$i
  ../setiathome -parms -stop_after_process
  sh $SETIDIR/xferwu &  # Launch xfer script, optional
 done
done
Basically, this will loop until "$var1" = end, which will never happen. Will crunch as long as the box is up, and there are WU to do. Probbably want to start this out of your system startup script, until I figure out a more clever way of running directly out of cron.

Now on to the clever cron jobs! First, you will have to decide how often you want to download/upload new WU. Pick a number that goes into 24 nicely if you are like me and like things nice and neat. I would say 6-8 hours is probbably plenty. I'll go with 8 in my example to be extra nice to Berkeley. Now, as far as I know, this cron type entry ONLY work in Linux. Check it out:
code:<HR>
Code:
* */8 * * * /home/you/xferwu & > /dev/null
Clever. Runs every 8 hours, in this case Midnight, 8am, and 4pm. If you put a 6 instead of an 8, it will run the script at Midnight, 6am, noon, 6pm etc. Make sense? Cool.

Now there is the barebones. Now we need to make it sexy. Logging options, better recovery from possible crunch stoppers, and so on. Feedback goood.

I have used the perl script lin-setibuf, and it works OK, but for some reason either it doesn't like kicking off an automatic xfer after a wu (this is in my plans, not tested yet, see above) or something. So I just setup a cron job to run every 6 hours to xfer the wu's out. lin-setibuf is a pretty cute program, but really has too MANY options and behaves strangely. (Heh, it *IS* perl ... overkill I would think. But has the advantage of being pretty 'cool' despite the fact that I don't like perl.) I think I am going to mangle my copies of lin-setibuf to automatically kick off another process upon completion fo the wu to at least ATTEMPT to exfer the wu. Then let the "download/upload" cron job kick off the rest? Still trying to figure out which will work best.
 
A key reason I stick with the simpler scripts is that I do the >> trick for result.sah not work_unit.sah or any other data. Everything I'm interested in is in the result file, so that's what I log.

I suppose if I checked to see of work_unit.sah existed first that would go a long way, though, to making loops more palable. In the end, though, the simple stuff worked so well, I decided against getting fancy. Sometimes, you can just plain overthink this stuff.

The simple script has a subtlety about it: If you do your cron launches cleverly enough, job 2 ends up "trailing" job 1 in the various directories so that you get the "two jobs at once" effect I so prize. Meanwhile, the xfer job comes in and cleans up, so there is almost always a WU available for the stop after process version to crunch.

I was able to run for months with virtually no interruptions with these exceedingly simple scripts and virtually no maintenance except to launch the upload script once a night (not even that often, sometimes) and do the odd "top" just to make sure all was well. It was.
 
I'd have to disagree with lots of things here... His method with loops is much simpler, not only code wise but usage wise as well. Why bother trying to perfect a cron entry so everything is timed just right? Let the script take care of making sure it's always running.

And about caching.... Saying it's overrated is a pretty thoughtless move. Remember about 2 months ago when the servers were down for a week? That's when caching shines. It also helps with the scripting. Instead of having to dance all over the place making sure something is always running and trying to time it so your overlapping clients actually overlap is pointless. Caching takes away theworries of all that.

Loops aren't over thinking, they're good program design. Scalability is key no matter what you're doing. With the loop all he needs to do is add a few more numbers to the foreach statement. With your "simple" mehtod you'd have to copy and paste a bunch then go back and edit every single line of code. You call that simple? Maybe to a masochist....

Log "trashing".... seems more of a PEBKAC to me. Odds are if the servers go down you'll know about within a short time (goodness knows it'll be plastered all over this forum!) When it does you can stop your scripts after the units finish up. Then they won't spit tons of errors into your log. If you don't you have no right to whine about "trashed log files" since you could've very easily stopped it. Or you could add a few extra lines and either weed out error messages or send them to another log.
 
SLWB writes:

I'd have to disagree with lots of things here... His method with loops is much simpler, not only code wise but usage wise as well. Why bother trying to perfect a cron entry so everything is timed just right? Let the script take care of making sure it's always running.

How much actual experience do you have with either one? I've tried both. It's always amusing when someone impeaches actual experience. I never said loops wouldn't work -- I said that it had problems and I'd rather do the "straight" scripts because they have advantages.

The problems are real. Particularly if you do some logging (as the example above showed). The problem is this: When there's an outage, you end up getting several copies of the completed-but-not-uploaded-WU information into your log. I know -- I've been there, done that, hand-edited it out, wanted to stop.

And, the timing for crond isn't very hard to get right.

Moreover, I didn't show an even simpler form whereby you have continuous internet support that I've also used. It works like this:

cron entry one starts the job.
cron entry two kills the job.

This allows me to run "hands free" when I can't run 24 by 7 and it doesn't require any loops, either. By putting the "kill" entry maybe five minutes ahead of the "start" entry, I can run 24 by 7 (less five inconsequential minutes, two if I'm braver) and be reasonably sure that jobs are running all the time when I do the simple scripts or when I do the approach above for continuous connection.

When I have two such entries for each type, I have my two jobs and all the caching I really need. It also tends to get me over situations where one of the jobs dies. If the looping job dies in the right way, then nothing is running on that machine (I'll concede that if it dies another way, it goes on to the next directory -- I've seen both).

Note critically, however, that the loop approach also pseudo-dies when one job ends up in the "wait an hour and try again" situation. With two jobs, that practically never happens for both at once, so I always am running.

Two jobs running tends to allow me to find, when I get onto a machine I've ignored for days, that no matter what happens (including my own problems) one of the jobs has survived. The single loop approach doesn't necessarily give you that. My approach does and I know that it has real world benefit, because this is the other reason I stopped looping and went to it.

Note well that it is harder to run multiple jobs with looping approaches, because you can end up with a lot more than two total jobs, since the looping approach goes to multiple directories. That problem tends to make it more "cron-proof" which is, in my experience, a disadvantage overall.

There's a lot more to my approach than meets the eye. Maybe I could figure out how to marry multiple jobs and loops, but I've never taken the trouble. This works easily enough for me.

And about caching.... Saying it's overrated is a pretty thoughtless move. Remember about 2 months ago when the servers were down for a week? That's when caching shines. It also helps with the scripting. Instead of having to dance all over the place making sure something is always running and trying to time it so your overlapping clients actually overlap is pointless. Caching takes away the worries of all that.

Oddly, we're not in as much disagreement as you think. Don't rely on the memories, painful as they are: Do the math. I've had to. I know we lost that week when I wrote it.

I've been forced by circumstances at work to run without caching of any kind for very extended periods. If you care to look at the number seven slot in TLC, you'll see that I wasn't exactly hurt bad by not caching.

I've lost something like 10 days total since around July or so when I started serious crunching on iSeries, including your seven. There just haven't been that many extended outages. The outage doesn't really begin until the current WU stops crunching. On 3.03, that's a lot longer than it was.

There have been many outages, but the majority didn't even last one day. Two WUs per CPU would have gotten a typical machine through most of those, so the loss would be about 7 days (and, I don't remember the outage being a full seven days, but I'll take your number). I've been seriously crunching for about 304 days (about 10/12 of a year) and so 10/304 is. . .about three percent.
That's what caching gives you, over a long period of time: Three percent. Earlier in the project, it was worth more, because outages were more plentiful, but this is now.

And, keep in mind that my 3 percent is for your model of one job per CPU and even presumes (for short duration outages) that running out of WU is a certainty (where, in fact, the outage must on average exceed 1/2 WU time to be an outage at all for one job, 3/4 of a WU for two).

So, I'll live with the three per cent. If the last three per cent matters that much to you, cache away.

Personally, if I can arrange my machine so that I don't have to pay any attention to it at all for days and weeks (as my approach does), I think I gain more than that three per cent because of the times the machine isn't idle due to some unexpected termination or a "wait an hour and try again" situation that does arise from time to time.

The second job buys me coverage over that situation, except in the unlucky case where both terminate about the same time. However, the WUs vary enough that, in fact, they do end up about a half WU apart most of the time

The hidden key, perhaps, is that I found having cron entries indespensible anyway for truly "hands free" operation. You want to be able to have your SETI job restart "no matter what kills it" which is something a single job, running in a loop, turns out not to gurantee.

Now, if you can tend the machine (as I imply one would for the by-hand upload case) this is all a lot less critical and more a matter for personal taste.

[This message was edited by Larry Loen on April 24, 2001 at 21:58.]
 
/me shot himself in the foot with this one...

How much actual experience do you have with either one?

Enough to know a loop makes it much more manageable. I wrote something similar to this for folding. Think Neptune on steroids.

Note critically, however, that the loop approach also pseudo-dies when one job ends up in the "wait an hour and try again" situation

Not true at all. Looks at his scripts again. It loops through just downloading them. The other loops through just crunching them. There is no opportunity for it to get stuck waiting for a connection attempt after crunching because it never tries to connect.

Having a loop through script with solo jobs probably isn't any less reliable than having dual jobs. I don't know about shell script, but in perl when you launch an outside app the script pauses until the outside job is finished. If thats the case and seti dies it *should* go on to the next one. That is just speculation though.

Loops and dual jobs is probably very possible. Have the loop only go through the odd numbers. It runs seti in the directory of the loop. Then it calls a second script passing the argument of the loop # plus 1. The outside script sleeps for x time before starting the second instance of seti so you get a staggering effect. The trick is launching the outside script as a child that doesn't halt the main script (I know thats possible, I just have no clue how to since my linux knowledge stops after ls, cd, and pico (thanks Councilor!!! ;) ))

/me weeps for the poor 3.03 users
/me does a happy dance for the folders, rc5ers, and genomers that are unhindered by artifical limitations

Good point on the 3%, but think how much of an edge on the competition you could get if you cached and they didn't! It boggles the mind. Especially to little fishes like me who don't have phat As/400's :(

So from all this I guess we learned you do it your way, I do it mine, and neither of us have to post a whole crap load of stuff....
 
Fine point. You wrote:

There is no opportunity for it to get stuck waiting for a connection attempt after crunching because it never tries to connect.

There is an important asymmetry in SETI here that matters a bit. Obviously, the upload option tries to reconnect. However, IIRC, the -stop_after_process option will also attempt to connect if there is no work unit. So, if there's a problem where the upload happens, removing result.sah, and the download doesn't, thus not supplying a new work_unit.sah, the cruch side (if memory serves) will try and get the WU and then, sometimes, hang, especially if there's an intermittent connection and one doesn't notice the failure on the transfer, however done.

These are the sorts of itty bitty once-in-a-while problems I bumped into (and I split between the supposed "crunch only" and "upload" options, too). Individually, they were nothing; collectively, there were just enough dumb little special cases that it became, finally, too much hassle.

Again, all of this can be made to work tolerably with loops anyway.

I've used loops and gotten by. It's also true that all these niggling problems eventually had me throwing in the towel and avoiding loops. It got to the point that I feared the problems on "my side" more than on SETI's.

That's really all this boils down to. Pick your poison. Or maybe, choose based on how much time you've got to supervise a given machine. If you've got a handful of machines, then none of this is a big hairy deal. I've got just enough machines available at work that this all got to be too much, especially if I signed on weekly at most. For the home machines, loops are more feasible, though as a matter of taste, I didn't use them, being familiar with the other technique.

But, its not like it is terribly flawed, especially for home use. If I had but two machines, maybe I'd go with loops, especially to optimize caching. Though I should point out, that on my at-home machines, I was caching, just not doing so by looping.

If you or someone can solve the crond restart problem, however, loops will again become more interesting to me, because I can get around all this petty stuff on the client side with higher probability.

In my case, I wasn't "thinking Neptune"; I was optimizing something different. Think "never sign on and still get your WU no matter what".
 

JessF

Ars Scholae Palatinae
737
It is clear from this thread that caching/scripting has personal preferences - i knew that allready when I started it. It was meant to help people trying to make their own.

I use the scripts on my personal machine, which is why I have some output. The machine only has dialup access so i run the "xfer"-script manually when I have access. So I'll see it if the download fails.

Sometimes the download fails, but running the "xfer"-script again fixes that - apparently when the download fails the client removes the bad WU before exiting. Because of this - if there was a "bad" download - the crunching script will skip the dir.

I don't think I have ever had a "waiting" client when using these scripts.

The scripts did hose my log once (before I added the sleep) - I wasn't home for a few days, so the cache ran out :(
 

Hagabard

Ars Scholae Palatinae
993
Well, I've been using it for the better part of a week on my Linux machines now. Now that I am using the right switches to launch it, I don't even need cron. (Unless the system has been restarted... ARGH!) This is important for me because on one machine cron is disabled. (An accident, but the admin doesn't feel like fixing it yet.) And it also happens to cache 9 work untis in my current config so there is plenty to deal with the intermittancy of some of the INTERNET connections these boxes are on, and the occasional SETI outage. (DLS & Cable go down ALOT for me and my friends. :( )

For those that are going to check it out I use this command line:
./lin-setibuf -Dsd &
That starts off in Daemon mode, start processing, download untis (and send results). It works pretty well. Then I just put this in my .bash_login so when I login checking is easy:
seti/lin-setibuf -t
uptime
This displays the current status of WU like this, and the current uptime and load average of the machine:
code:<HR>
Code:
Using `/home/hagabard/.lin-setibufrc' as configuration file.
lin-setibuf - Version 1.1.5
Verifing stack status...
WU #1 - Progress:   0.00%  -  0% |          | 100
WU #2 - Progress:   0.00%  -  0% |          | 100
WU #3 - Progress:   0.00%  -  0% |          | 100
WU #4 - Progress:   0.00%  -  0% |          | 100
WU #5 - Progress:   0.00%  -  0% |          | 100
WU #6 - Progress:   0.00%  -  0% |          | 100
WU #7 - Progress:  40.51%  -  0% |====      | 100
WU #8 - Progress:   0.00%  -  0% |          | 100
WU #9 - Progress:   0.00%  -  0% |          | 100
  1:14am  up 17:20,  1 user,  load average: 0.00, 0.00, 0.00

This shows that the system was rebooted almost 18 hours ago. It's showing that all the other WU are fresh, and we are currently working on WU#7 at 40% complete. Since SETI is not running (see load average) to start up lin-setibuf from WU #7 I would use this command:
seti/lin-setibuf -Dsd -f 7 &
And logout and come back and check later. You can also enable Email notification and if you don't recieve an email, you know something happened and you need to login. Supports logging and other interesting goodies.

The onyl feature I wish I could add would be a simple cron job (can't on this particular box) that would check the load average of the machine, and if it isn't where it is supposed to be, killall lin-setibuf and killall setiathome and restart it, possibly from whatever WU it is working on. I havn't figured all of that out yet. :)

But for my money, this is the best (single processor) solution I have found yet. I'm testing another program out on my dual box now. It's more primitive, but it seems to work. And if I can get it to behave a little nicer I'll probbably switch to using that. Stay tuned.

Ohh you want more output? Here is another box:
code:<HR>
Code:
Using `/home/hagabard/.lin-setibufrc' as configuration file.
lin-setibuf - Version 1.1.5
Verifing stack status...
WU #1 - Analysis Complete. - Results found:  7
WU #2 - Analysis Complete. - Results found:  8
WU #3 - Progress:  44.59%  -  0% |====      | 100
WU #4 - Progress:   0.00%  -  0% |          | 100
WU #5 - Progress:   0.00%  -  0% |          | 100
WU #6 - Progress:   0.00%  -  0% |          | 100
WU #7 - Progress:   0.00%  -  0% |          | 100
WU #8 - Progress:   0.00%  -  0% |          | 100
WU #9 - Progress:   0.00%  -  0% |          | 100
 10:17am  up  1:49,  2 users,  load average: 1.00, 1.00, 0.91

This shows that I have 2 workuntis done and are ready to be sent off, and that the machine was restarted just under two hours ago, but SETI is running and at about 45% on this WU.

Anyway, it works but needs some babysitting. I am trying to find the best possible solution and I think the only way to make it work the way I want is to do it myself.
 
Status
Not open for further replies.