README.rst 11.2 KB
Newer Older
1 2 3
======================
 Parallel Job Manager
======================
André Anjos's avatar
André Anjos committed
4

5 6 7
The Job Manager is python wrapper around SGE utilities like ``qsub``, ``qstat`` and ``qdel``.
It interacts with these tools to submit and manage grid jobs making up a complete workflow ecosystem.
Currently, it is set up to work with the SGE grid at Idiap, but it is also possible to modify it to be used in other SGE grids.
André Anjos's avatar
André Anjos committed
8

9 10
Since version 1.0 there is also a local submission system introduced.
Instead of sending jobs to the SGE grid, it executes them in parallel processes on the local machine, using a simple scheduling system.
11

André Anjos's avatar
André Anjos committed
12

13 14 15 16 17 18 19 20

Submitting jobs to the SGE grid
+++++++++++++++++++++++++++++++

Every time you interact with the Job Manager, a local database file (normally named ``submitted.sql3``) is read or written so it preserves its state during decoupled calls.
The database contains all information about jobs that is required for the Job Manager to:

* submit jobs of any kind
André Anjos's avatar
André Anjos committed
21 22 23 24 25 26
* probe for submitted jobs
* query SGE for submitted jobs
* identify problems with submitted jobs
* cleanup logs from submitted jobs
* easily re-submit jobs if problems occur
* support for parametric (array) jobs
27
* submit jobs with dependencies, which automatically get killed on failures
André Anjos's avatar
André Anjos committed
28

29
Many of these features are also achievable using the stock SGE utilities, the Job Manager only makes it dead simple.
André Anjos's avatar
André Anjos committed
30

31 32
If you really want to use the stock SGE utilities, the gridtk defines some wrapper scripts that allows to use ``qsub``, ``qstat`` and ``qdel`` without the need of the SETSHELL command.
For example, you can easily use ``qstat.py`` to query the list of your jobs running in the SGE grid.
33

André Anjos's avatar
André Anjos committed
34

35 36 37 38 39 40 41
Submitting a simple job
-----------------------

To interact with the Job Manager we use the ``jman`` utility.
Make sure to have your shell environment setup to reach it w/o requiring to type-in the full path.
The first task you may need to pursue is to submit jobs.
Here is how::
André Anjos's avatar
André Anjos committed
42

43
  $ jman -vv submit myscript.py --help
44 45
  ... Added job '<Job: 1> : submitted -- /usr/bin/python myscript.py --help' to the database
  ... Submitted job '<Job: 6151645> : queued -- /usr/bin/python myscript.py --help' to the SGE grid.
André Anjos's avatar
André Anjos committed
46 47

.. note::
48

49 50 51 52
  The command ``submit`` of the Job Manager will submit a job that will run in a python environment.
  It is not the only way to submit a job using the Job Manager.
  You can also use ``submit`` a job that considers the command as a self sufficient application.
  Read the full help message of ``jman`` for details and instructions.
André Anjos's avatar
André Anjos committed
53

54

André Anjos's avatar
André Anjos committed
55 56 57
Submitting a parametric job
---------------------------

58 59 60
Parametric or array jobs are jobs that execute the same way, except for the environment variable ``SGE_TASK_ID``, which changes for every job.
This way, your program controls, which bit of the full job has to be executed in each (parallel) instance.
It is great for forking thousands of jobs into the grid.
André Anjos's avatar
André Anjos committed
61

62 63
The next example sends 10 copies of the ``myscript.py`` job to the grid with the same parameters.
Only the variable ``SGE_TASK_ID`` changes between them::
André Anjos's avatar
André Anjos committed
64

65 66 67
  $ jman -vv submit -t 10 myscript.py --help
  ... Added job '<Job: 2> : submitted -- /usr/bin/python myscript.py --help' to the database
  ... Submitted job '<Job: 6151646> : queued -- /usr/bin/python myscript.py --help' to the SGE grid.
André Anjos's avatar
André Anjos committed
68

69 70
The ``-t`` option in ``jman`` accepts different kinds of job array descriptions.
Have a look at the help documentation for details with ``jman --help``.
André Anjos's avatar
André Anjos committed
71

72

André Anjos's avatar
André Anjos committed
73 74 75
Probing for jobs
----------------

76 77
Once the job has been submitted you will noticed a database file (by default called ``submitted.sql3``) has been created in the current working directory.
It contains the information for the job you just submitted::
André Anjos's avatar
André Anjos committed
78

André Anjos's avatar
André Anjos committed
79
  $ jman list
André Anjos's avatar
André Anjos committed
80

81 82 83 84 85 86 87 88 89 90
         job-id           queue        status            job-name                 dependencies                      submitted command line
  ====================  =========  ==============  ====================  ==============================  ===========================================
        6151645           all.q        queued             None                        []                 /usr/bin/python myscript.py --help
    6151646 [1-10:1]      all.q        queued             None                        []                 /usr/bin/python myscript.py --help

From this dump you can see the SGE job identifier including the number of array jobs, the queue the job has been submitted to, the current status of the job in the SGE grid, the dependencies of the job and the command that was executed in the SGE grid.
The ``list`` command from ``jman`` will show the current status of the job, which is updated automatically as soon as the grid job finishes.
Several calls to ``list`` might end up in

.. note::
91

92 93
  This feature is new since version 1.0.0. There is no need to refresh the
  database any more.
André Anjos's avatar
André Anjos committed
94 95


96 97
Submitting dependent jobs
-------------------------
André Anjos's avatar
André Anjos committed
98

99 100
Sometimes, the execution of one job might depend on the execution of another job.
The JobManager can take care of this, simply by adding the id of the job that we have to wait for::
André Anjos's avatar
André Anjos committed
101

102 103 104
  $ jman -vv submit --dependencies 6151645 -- /usr/bin/python myscript.py --help
  ... Added job '<Job: 3> : submitted -- /usr/bin/python myscript.py --help' to the database
  ... Submitted job '<Job: 6151647> : queued -- /usr/bin/python myscript.py --help' to the SGE grid.
105 106

Now, the new job will only be run after the first one finished.
André Anjos's avatar
André Anjos committed
107

108
.. note::
109

110 111
  Please note the ``--`` between the list of dependencies and the command.

André Anjos's avatar
André Anjos committed
112 113 114 115

Inspecting log files
--------------------

116 117
If jobs finish, the result of the executed job will be shown in the ``list``.
In case it is non-zero, might want to inspect the log files as follows::
André Anjos's avatar
André Anjos committed
118

119
  $ jman report --errors-only
120 121 122
  ...
  <Job: 6151646  - 'jman'> : failure (2) -- /usr/bin/python myscript.py --help
  /usr/bin/python: can't open file 'myscript.py': [Errno 2] No such file or directory
André Anjos's avatar
André Anjos committed
123 124 125

Hopefully, that helps in debugging the problem!

126

André Anjos's avatar
André Anjos committed
127 128 129
Re-submitting the job
---------------------

130
If you are convinced the job did not work because of external conditions (e.g. temporary network outage), you may re-submit it, *exactly* like it was submitted the first time::
André Anjos's avatar
André Anjos committed
131

132
  $ jman -vv resubmit --job-id 6151645
133 134
  ... Deleting job '6151645'
  ... Submitted job '<Job: 6151673> : queued -- /usr/bin/python myscript.py --help' to the SGE grid.
André Anjos's avatar
André Anjos committed
135

136 137 138
By default, the log files of the old job are deleted during re-submission.
If for any reason you want to keep the old log files, use the ``--keep-logs`` option.
Notice the new job identifier has changed as expected.
139 140 141 142


Stopping a grid job
-------------------
143 144
In case you found an error in the code of a grid job that is currently executing, you might want to kill the job in the grid.
For this purpose, you can use the command::
145 146 147

  $ jman stop

148 149
The job is removed from the grid, but all log files are still available.
A common use case is to stop the grid job, fix the bugs, and re-submit it.
150

André Anjos's avatar
André Anjos committed
151 152 153 154

Cleaning-up
-----------

155 156
If the job in question will not work no matter how many times we re-submit it, you may just want to clean it up and do something else.
The Job Manager is here for you again::
André Anjos's avatar
André Anjos committed
157

158 159
  $ jman -vvv delete
  ... Deleting job '8258327' from the database.
André Anjos's avatar
André Anjos committed
160

161 162 163
In case, jobs are still running or queued in the grid, they will be stopped before they are removed from the database.
By default, all logs will be deleted with the job.
Inspection on the current directory will now show you everything concerning the jobs is gone.
164 165


166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
New from version 1.0
++++++++++++++++++++

If you know the gridtk in versions below 1.0, you might experience some differences.
The main advantages of the new version are:

* When run in the grid, the jobs now register themselves in the database.
  There is no need to refresh the database by hand any more.
  This includes that the result (an integral value) of the job execution is available once the job is finished.
  Hence, there is no need to rely on the output of the error log any more.

  .. note::
    In case the job died in the grid, e.g., because of a timeout, this mechanism unfortunately still doesn't work.
    Please try to use ``jman -vv communicate`` to see if these kinds of errors happened.

* Jobs are now stored in a proper .sql3 database.
  Additionally to the jobs, each array job now has its own SQL model, which allows to store status and results of each array job.
  To ``list`` the array jobs as well, please use the ``--print-array-jobs`` option.

* In case you have submitted a long list of commands with inter-dependencies, the Job Manager can now kill waiting jobs in case a dependent job failed.
  Simply use the ``--stop-on-failure`` option during the submission of the jobs.

* Now, the verbosity of the gridtk can be selected more detailed.
  Simply use the ``-v`` option several times to get 0: ERROR, 1: WARNING, 2: INFO, 3: DEBUG outputs.
  A good choose is probably the ``-vv`` option to enable INFO output.
  Please note that this is not propagated to the jobs that are run in the grid.

  .. note::
194

195 196 197 198 199 200
    The ``-v`` options must directly follow the ``jman`` command, and it has to be before the action (like ``submit`` or ``list``) is chosen.
    The ``--database`` is now also a default option, which has to be at the same position.

* One important improvement is that you now have the possibility to execute the jobs **in parallel** on the **local machine**.
  Please see next section for details.

201
Running jobs on the local machine
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
---------------------------------

The JobManager is designed such that it supports mainly the same infrastructure when submitting jobs locally or in the SGE grid.
To submit jobs locally, just add the ``--local`` option to the jman command::

  $ jman --local -vv submit /usr/bin/python myscript.py --help


One important difference to the grid submission is that the jobs that are submitted to the local machine **do not run immediately**, but are only collected in the ``submitted.sql3`` database.
To run the collected jobs using 4 parallel processes, simply use::

  $ jman --local -vv run-scheduler --parallel 4

and all jobs that have not run yet are executed, keeping an eye on the dependencies.

.. note::
218

219 220 221
  The scheduler will run until it is stopped using Ctrl-C.
  Hence, as soon as you submit new (local) jobs to the database, it will continue running these jobs.
  If you want the scheduler to stop after all scheduled jobs ran, please use the ``--die-when-finished`` option.
222

223 224
Another difference is that by default, the jobs write their results into the command line and not into log files.
If you want the log file behavior back, specify the log directory during the submission::
225

226
  $ jman --local -vv submit --log-dir logs myscript.py --help
227

228
Of course, you can choose a different log directory (also for the SGE submission).
229

230 231
Furthermore, the job identifiers during local submission usually start from 1 and increase.
Also, during local re-submission, the job ID does not change.
232 233


234 235
Using the local machine for debugging
-------------------------------------
236

237 238
One possible use case for the local job submission is the re-submission of jobs to the local machine.
In this case, you might re-submit the grid job locally::
239

240
  $ jman --local -vv resubmit --job-id 6151646 --keep-logs
241

242
(as mentioned above, no new ID is assigned) and run the local scheduler::
243

244
  $ jman --local -vv run-scheduler --no-log-files --job-ids 6151646
245

246
to print the output and the error to console instead of to log files.
247