Toolserver:SGE for beginners

The toolserver uses SGE (previously Sun Grid Engine) for distribute long-running jobs (like bots) over the cluster. SGE is very flexible, but it can also be confusing from time to time. So this page tells just simple recipes, for more details see SGE. SGE thinks in the concept of jobs and resources. SGE is like a big company with different employees. You can call the firm and say "I need you to build me a house" (that's the job) and the company will look when its employees (that's the resources) have free time and build you a house. The only difference is that SGE is not so smart as a manager and you need to tell SGE what you need (how many bricklayers, carpenters, plumbers, etc.). But it is smart enough to only execute your job when all needed craftsmen are available (human managers are not so smart from time to time…). If not enough free craftsmen are around the job is stored in a queue and waits there until all needed craftsmen are around again. Please do not think "I just not tell them that I need plumbers so my job is execute faster" because
 * there may be no plumbers around when you need them (so you get a house without tubes)
 * it's unfair against other honest people.

The beginning
You can only use SGE if your job can run without you (that's called non-interactive). If you run your program in cron already, it is non-interactive. If you are unsure just start your program on the command-line. Does it ask any questions? Do you have to type something in? Then it is interactively and you can not use SGE. If your program is non-interactive (because you know or you tested) than the next test is: Start it on the command-line and see if it runs. If not: Fix it (maybe it misses parameters or required software or libraries are missing – it is not focus of this How-To to fix this, sorry). If your program runs than you need to create a so called wrapper-script next. A wrapper-script (short wrapper) does nothing other than execute another program or script. You will see later why we need it. Lets assume that your program is in the sub-directory "bot" in your home, it is called fixit.py and it needs the parameter "-login" to run. Lets also assume that your login-name is smith. So until now your home looks like to following: / /bot fixit.py The complete path to your fixit.py is /home/smith/bot/fixit.py. Create now a wrapper-file; it should end with ".sh" in your bot-subdirectory. In this example it's called "start_fixit.sh" and looks like the following: Not very spectacular yet. Don't forget to make it executable with chmod u+x "/home/smith/bot/start_fixit.sh"

You should now be able to start your bot with just calling /home/smith/bot/start_fixit.sh on the command-line. Until now no SGE is involved in any way. That will change in the next chapter.

The very basics
For every job you need to tell SGE about 2 resources: Runtime and memory-usage. The runtime is how long your job will run. This can be a few minutes (a bot that puts the flower-of-the-day on a main-page of a wiki), some hours (a bot that cleans up talk-pages), days (a bot that maintenances a working-site on a wiki) or forever (like an IRC-bot). Normally your task should NOT run forever; let it stop from time to time (to free memory and give other people a chance to run jobs). A good runtime of a forever bot is 3 to 7 days – it is no problem to start the bot again short after. To tell SGE about the runtime (and every other resources too) you have to set a parameter in the script. The parameter for the runtime is called h_rt and expects its value in the format [dd:]hh:mm:ss. Thats looks more complicated as it is, see the following examples Every resource you need is insert in the wrapper in the following way: Lets assume that your fix-it-bot runs 15 minutes for normal. You should always add a safety buffer to every resource, so we will tell SGE that your job will run 20 minutes. So you will add to the beginning of your wrapper. The wrapper looks now like the following:
 * 00:03:00 → 3 minutes
 * 01:00:00 → 1 hour
 * 04:00:00:00 → 4 days
 * 01:20:01:00 → 1 day, 20 hours and 1 minute.
 * 1) -l resource_name=value
 * 1) -l h_rt=00:20:00

Now we have to think about the second important parameter: memory using. Your program (whatever it is) will use memory during its run. SGE needs to know how many so it will not start your job on a server where not enough memory is left.

For every job you need to know 2 things:
 * How long should be task run?
 * How many memory will it use?


 * Does it need one or more SQL-connections (and to where)?