Using Allas in batch jobs¶
In this tutorial you will learn
- How to use Allas inside batch jobs
Preparations¶
On Roihu,
allas-conf sets up a persistent S3 connection by default.
Unlike the older Swift protocol (which is only valid for eight hours), the S3
connection does not expire, so there is no need to worry about a batch job
starting late or running longer than eight hours.
-
Load the Allas module and open a connection to Allas interactively before submitting your batch job:
Re-running
allas-conflater (e.g. to switch to a different project) updates the generics3allas:rclone endpoint to point at the new project. This can affect batch jobs that are still queued or running! To avoid this, prefer the project-specific endpoints3allas-project_<id>:(also created byallas-conf) in your batch scripts instead ofs3allas:.If you specifically need the Swift protocol instead (e.g. to access multiple projects from the same session), see Using the legacy Swift protocol below.
-
Choose a file from Allas. The file should have text in it. You can use the one you created in one of the earlier tutorials, or any other text file you have in Allas:
-
Create a new batch job script. First open a new text file with the command:
-
Copy one of the batch job scripts below to the text file you are editing. Replace
<project_number>-$USERto match your bucket name and<filename>with the name of the file you have in Allas. Remember to also define your billing project (--account).#!/bin/bash #SBATCH --job-name=my_allas_job # Name of the job visible in the queue #SBATCH --account=<project> # Choose the billing project. Has to be defined! #SBATCH --time=00:05:00 # Maximum duration of the job. Max: depends on the partition #SBATCH --mem-per-cpu=1G # How much RAM is reserved for one processor #SBATCH --partition=test # Job queues (CPU): interactive, test, small, medium, large, longrun, hugemem, hugemem_longrun #SBATCH --output=allas_output_%j.txt # Name of the output-file #SBATCH --error=allas_errors_%j.txt # Name of the error-file bucketname=<project_number>-$USER # Replace with your bucket name, e.g. 2001234-username filename=<filename> # Replace with your file name a-get $bucketname/$filename # Bucket name / file name wc -l $filename > $filename.num_rows # file name a-put -b $bucketname $filename.num_rowsSince the S3 connection set up in Preparations is persistent, no extra connection code is needed inside the batch script -- just make sure you have run
allas-confinteractively beforehand.#!/bin/bash #SBATCH --job-name=my_allas_job # Name of the job visible in the queue. #SBATCH --account=<project> # Choose the billing project. Has to be defined! #SBATCH --time=00:05:00 # Maximum duration of the job. Max: depends on the partition. #SBATCH --mem-per-cpu=1G # How much RAM is reserved for one processor. #SBATCH --partition=test # Job queues (CPU): interactive, test, small, medium, large, longrun, hugemem, hugemem_longrun #SBATCH --output=allas_output_%j.txt # Name of the output-file. #SBATCH --error=allas_errors_%j.txt # Name of the error-file. bucketname=<project_number>-$USER # Replace with your bucket name, e.g. 2001234-username filename=<filename> # Replace with your file name rclone copy s3allas:$bucketname/$filename ./ wc -l $filename > $filename.num_rows rclone copy $filename.num_rows s3allas:$bucketnameIf you're running multiple batch jobs across different projects at the same time, use the project-specific endpoint (
s3allas-project_<id>:) instead ofs3allas:to avoid a laterallas-confrun changing which project your job'srclonecommands point to. -
Submit the batch job with the command:
-
Monitor the progress of your batch job:
Using the legacy Swift protocol¶
Roihu defaults to S3, so the steps above are the recommended approach for
most users. Use this section only if you specifically need Swift, e.g. to
access multiple projects within the same eight-hour session.
The
allas-conf --swift command opens a Swift-based Allas connection that
is valid for eight hours. In interactive use this is not a problem, since
allas-conf can simply be run again to extend the connection. In batch jobs,
however, the job may still be queuing or running once the connection expires.
-
Load the Allas module and open a Swift connection with the
-koption:- The
-koption stores your password in the environment variable$OS_PASSWORD. With this variable defined, you no longer need to input your password when you re-executeallas-confwith the-koption and the Allas project name.
If you mistype your password when using the
-koption, you must use the commandunset OS_PASSWORDbefore you can try again. - The
-
Refresh the connection with the command:
When
$OS_PASSWORDis set, thea-commands(a-put,a-get,a-list,a-delete) automatically refresh the Allas connection when the commands are executed in a batch job, so thea-commandsbatch script above works with Swift as-is, once the connection has been opened this way. -
If you use
rcloneinstead of thea-commands, you need to explicitly refresh the Swift connection inside the batch script itself, since the$OS_PASSWORDauto-refresh only applies toa-commands:#!/bin/bash #SBATCH --job-name=my_allas_job # Name of the job visible in the queue. #SBATCH --account=<project> # Choose the billing project. Has to be defined! #SBATCH --time=00:05:00 # Maximum duration of the job. Max: depends on the partition. #SBATCH --mem-per-cpu=1G # How much RAM is reserved for one processor. #SBATCH --partition=test # Job queues (CPU): interactive, test, small, medium, large, longrun, hugemem, hugemem_longrun #SBATCH --output=allas_output_%j.txt # Name of the output-file. #SBATCH --error=allas_errors_%j.txt # Name of the error-file. bucketname=<project_number>-$USER # Replace with your bucket name, e.g. 2001234-username filename=<filename> # Replace with your file name # Make sure the connection to Allas is open source /appl/soft/manual/general/common/allas/allas-cli-utils/allas_conf --swift -f -k $OS_PROJECT_NAME rclone copy allas:$bucketname/$filename ./ wc -l $filename > $filename.num_rows # Make sure the connection to Allas is open source /appl/soft/manual/general/common/allas/allas-cli-utils/allas_conf --swift -f -k $OS_PROJECT_NAME rclone copy $filename.num_rows allas:$bucketnameNote that the Swift-configured
rcloneremote is namedallas:, nots3allas:(which is reserved for the S3 connection).
More information¶
- Docs CSC: Using Allas in batch jobs