[go: nahoru, domu]

Jump to content

Wikimedia Labs/Tool Labs/Help: Difference between revisions

From mediawiki.org
Content deleted Content added
→‎How: note about where you can submit from
Line 40: Line 40:


The basic principle of running jobs is fairly straightforward:
The basic principle of running jobs is fairly straightforward:
*You '''''submit''''' a '''''job''''' to a work queue;
*You '''''submit''''' a '''''job''''' to a work queue from a submission server (-login, -dev) and the web servers.;
*The gridengine master finds a suitable execution host to run the job on, and starts it there once resources are available; then
*The gridengine master finds a suitable execution host to run the job on, and starts it there once resources are available; then
*As it runs, your job will send their output and errors to files until it completes or it is aborted.
*As it runs, your job will send their output and errors to files until it completes or it is aborted.

Revision as of 14:21, 22 April 2013

Access

The first step is to get an account on Wikitech, the general interface to all things Labs. On the account creation form is a field "Instance shell account name"; that will be your Unix username on all Labs project.

In order to access Labs servers by SSH, you also need to provide a public SSH key on the 'OpenStack' tab of your Wikitech preferences once you have an account.

Add help for Windows and other less experienced users here.

Getting access to the Tool Labs

Once you have a Labs account, you can request access to the tools project (you may look at the project page to see a list of current admins).

The tool labs has a public IP; once you have a tool labs account, you can connect by SSH to tools-login.wmflabs.org (including for SFTP and WinSCP). You will need to use the shell account name you provided when creating your Wikitech account, and the private key matching the public key you supplied for authentication.

Tool account

The primary concept of the Tool Lab's organization is the tool account; at its core this is a unix uid-gid pair named local-toolname which is intended to run the actual tool. Maintainers may have more than one tool account, and tool accounts may have more than one maintainer.

Right now, you have to request a tool account from one of the project administrators; the plan is to make available an interface on wikitech where tool maintainers will be able to create them at need.

The unix group has as its members the tool account itself, as well as the user accounts of the maintainers of the tool. Every member of that group has the authorization to sudo to the tool account.

Along with the unix uid, the following resources are provided by default:

  • A home directory on shared storage: /data/project/toolname
  • A web URI mapped to its ~/public_html: http://tools.wmflabs.org/toolname
  • A mysql database for local use (the credentials to which are stored in ~/.my.cnf)
  • Access to the continuous and task queues of the compute grid
Hint
As a convenience, tool maintainers can switch to the tool account with:
maintainer@tools-login:~$ become toolname
local-toolname@tools-login:~$

Grid engine

Every non-trivial task performed by tools should be dispatched by the grid engine so that a suitable place to run them is found with sufficient resources. Gridengine is highly flexible system for assigning resources to jobs, including parallel processing.

You can find documentation on the website; you may wish to pay particular attention to the qsub, qdel and qacct commands which are most important to users.

How

The basic principle of running jobs is fairly straightforward:

  • You submit a job to a work queue from a submission server (-login, -dev) and the web servers.;
  • The gridengine master finds a suitable execution host to run the job on, and starts it there once resources are available; then
  • As it runs, your job will send their output and errors to files until it completes or it is aborted.

You can submit jobs with qsub, modify some of their settings while they are waiting or running with qalter, get information on your queued and running jobs with qstat, and abort or cancel them with qdel. Those commands are very flexible, but a little complex at first – you might prefer to use the simplified alternatives below.

There are a few caveats to keep in mind when submitting a job:

  • You do not normally control which execution host will eventually run it, and should therefore only access directories that are shared between all hosts (specifically, /data/project and /home)
  • Your job's memory usage has a hard limit it cannot grow beyond. By default, that is 256MB but you can request more (or less) with qsub's -l h_vmem=memory or jsub's -m memory options.

    Bear in mind that jobs that request more memory may be penalized in priority and may have to wait longer before being run until sufficient resources are available.

Simple utilities

For most tasks, helper scripts are provided to abstract away some of the complexities of using the grid engine. Almost all use scenarios are covered with reasonable defaults by the jsub script:

jsub [options...] program [args...]

Options include many (but not all) qsub options, along with:
-stderr
Send errors that occur during the submission to stderr rather than the error output file (the errors while runnning the script always go do the error file).
-mem value
Request <value> amount of memory for the job. (Where value is number suffixed by 'k', 'm' or 'g')
-once
Only start one job with the name of this one (see below), fail if another is already started or queued.
-continuous
Start a self-restarting job on the continuous queue (default if invoked as jstart). Please see the section on continuous jobs below.
Some of the more useful qsub supported are:
-i, -o, and -e
Selects the file used for standard input, output and error of the job, respectively. By default, jsub will append stdout and stderr to the files jobname.out and jobname.err in the tool account's home directory, and will not have standard input.
-j
send standard output and error together to the output file
-sync y
Normally, jsub queues up the job and returns immediately. This allows you to wait for the job to be complete instead.
-cwd
Start the script in the same directory you invoked jsub from.
-N jobname
Pick a different job name (see below).

By default, jobs are allowed 256MB of memory; you can request more (or less) with the -m option but keep in mind that a job that requests more resources may be penalized in its priority and may have to wait longer before being run.

Job names

By default, jobs have the same name as the program, minus extensions. (For instance, if you had a program named foobot.pl which you started with jsub, the job's name would be foobot). You can pick a different name for the job when starting it (with the -N option of qsub and jsub); this name identifies the jobs on statuses, but can also be used to control it.

It's important to note that you can have more than one job, running or queued, bearing the same name. Some of the utilities that accept a job name may not behave as expected in those cases.

Simple, one-off job

The simplest scenario is when you want to run a job on demand that has a finite duration (at interval from cron, for instance, or from a web tool or the command line).

$ jsub program-or-script

Will schedule the job to be run as soon as possible, and put eventual output from the job to files in your home; this is done asynchronously in the background. If you need to wait until the job has completed (for instance, to do further processing on its output), you can add the -sync y option to the jsub command.

If you need to make certain that the job isn't running multiple times (such as when you invoke it from a crontab), you can add the -once option. If the job was already running or queued, it will simply mark the failed attempt in the error file and return immediately.

Continuous tasks (such as bots)

Continuous tasks have a dedicated queue, continuous, which has a slightly different setup:

  • Jobs started on that queue are automatically restarted if they, or the node they run on, crash
  • In case of outage or lack of resources, they will be stopped and restarted automatically on a working node
  • only tool accounts can start continuous jobs

The queue will not restart jobs that exited normally (i.e., were not killed) unless they are wrapped in a script to do so; starting a job with the -continuous option of jsub does so automatically until they exit normally with an exit value of zero, indicating completion.

One would normally start continuous jobs with the -once option as well so that they can be managed reliably with job and jstop utilities.

For convenience, there is an utility to start a continuous bot with reasonable default options: jstart script (which is equivalent to jsub -once -continuous script and accepts the same options. This would start the script program in continuous mode if it is not already running, making certain that it is kept running.

Job status
You can see the status of all your running and pending jobs with the qstat command. If you know that your job can only have on instance runnning (such as when you use the -once option when starting it) you can also use the job command to get its job id (or a more verbose status with -v). The latter is particularly useful from scripts or web services.
extended example

For instance:

local-xbot@tools-login:~$ qstat
job-ID  prior   name       user         state submit/start at     queue                          slots ja-task-ID 
-----------------------------------------------------------------------------------------------------------------
    120 0.50000 xbot       local-xbot   r     04/01/2013 21:00:00 continuous@tools-exec-01.pmtpa     1        

Reports that you have one job, with id 120 and name xbot that is currently running (r in the state column). You could also have used job:

local-xbot@tools-login:~$ job xbot
120
local-xbot@tools-login:~$ job -v xbot
Job 'xbot' has been running since 2013-04-01T21:00:00 as id 120
Stopping a running job
To stop a running job (or prevent it from being run if it had not already started), you can use the qdel job_number command. The job number was output when the job was started, or you can get it from the qstat command.

If you started the job with the jstart command, or you know there is only one job with the same name, then you can use the jstop jobname utility command.

Web services

Every tool account has a web interface made available (though, in cases of bots with no web interactivity, you may simply wish to have a static page that describes the tool, or a simple status report). Users do not and can not have a web directory in /home.

Published directories

Each tool account has two corresponding URI that are automatically made available from two directories in its home:

http://tools.wmflabs.org/toolname/
which maps to the tool's ~/public_html/
http://tools.wmflabs.org/toolname/cgi-bin
which maps to the tool's ~/cgi-bin/

The latter directory will attempt to run the files it contains as CGI scripts rather than display them. In addition, files in either directory that end with the .php or .php5 extensions will be run as PHP CGI scripts.

All CGI scripts must be marked executable, and are run with the permissions of the user account that owns the script. In almost all cases, you want to make certain that they are owned by the tool account.

The web server allows overrides of AuthConfig FileInfo Options=IncludesNOEXEC from .htaccess.

Cookies

Since all tools in the Labs reside under the same domain, you should prefix the name of any cookie you set with your tool's name. In addition, you should be aware that cookies you set may be read by every other web tool your user visits.

Accordingly, you should avoid storing privacy-related or security information in cookies. A simple workaround is to store session information in a database, and use the cookie as an opaque key to that information. Additionally, you can explicitly set a path in a cookie to limit its applicability to your tool; most clients should obey the Path directive properly.

Logs

The access logs for your tool's web interface are placed in the tool account's ~/access.log, in common format. Please note that the web logs are anonymized such that the user's IP address appears to be that of the local host. In general, the privacy policy will not allow logging of personally identifiable information by tool maintainers (including IP addresses); special permission from Foundation legal counsel would be required to get that information.

Error logs, because of limitations of the Apache web server, are not made directly available to tool maintainers. There is a workaround in place for PHP, which allows per-user logging (PHP error logs are placed in the tools account's ~/php_error.log), but until a newer version of Apache can be deployed it is recommended that you use your language's facilities to log errors to a file under the tool account's home.

In particular, however, this means that if you have a CGI which is unable to start you will not be able to see the error preventing it without help from a tool labs admin. There are a few common errors you can check against which cover most cases:

  • The CGI's file is not owned by the tool account
  • The CGI's file does not have its execute bits set
    (You can use the chmod command to set the script as executable)
  • The CGI is a script and does not start with a Unix "shebang" invocation, or it points to the wrong path:
    A unix "shebang" is the first line of a script that specifies the program meant to execute that script. It has the form
    #! /path/to/interpreter
    Where the path is, for instance, /usr/bin/perl for perl scripts. You can check the path to a language interpreter by using the which command:
    maintainer@tools-login:~$ which python
    would output the path to the python interpreter.

Database access

Every tool account automatically gets a database for general usage on the project itself. The information and credentials to that database are put automatically in the account's ~/.my.cnf on creation. Full control over that database is granted to the tool account (with grant option).

Normally, tools do not have access to create new databases dynamically; please consult with a project admin if you require that functionality.

(Soon) Tool accounts are also granted to the production database replicas, and may create and manage databases there at need. Because of technical limitations, actual revision text is not available on the replicas (but can be fetched at fairly high efficiency with the API).