Swiftorial Logo
Home
Swift Lessons
Tutorials
Learn More
Career
Resources

Azure Batch Tutorial

Introduction

Azure Batch is a cloud-based job scheduling service that allows you to run large-scale parallel and high-performance computing (HPC) applications efficiently in the cloud. With Azure Batch, you can scale out your compute resources, manage the execution of a large number of tasks, and only pay for what you use.

Prerequisites

Before you start working with Azure Batch, you need to have the following:

  • An Azure subscription
  • Basic knowledge of Azure services
  • Azure CLI installed on your local machine

Setting Up Azure Batch Account

To get started with Azure Batch, you need to create a Batch account. Follow the steps below to set up your Azure Batch account:

Step 1: Create a Resource Group

Open your terminal and run the following command to create a resource group:

az group create --name myResourceGroup --location eastus

Step 2: Create a Batch Account

Next, create a Batch account using the following command:

az batch account create --name mybatchaccount --resource-group myResourceGroup --location eastus

Step 3: Authenticate the Batch Account

Authenticate the Batch account using the following command:

az batch account login --name mybatchaccount --resource-group myResourceGroup --shared-key-auth

Creating a Batch Pool

A Batch pool is a collection of compute nodes (virtual machines). Follow the steps below to create a Batch pool:

Step 1: Create a Batch Pool

Run the following command to create a Batch pool:

az batch pool create --id mypool --vm-size Standard_A1_v2 --target-dedicated-nodes 2 --image canonical:ubuntuserver:18.04-LTS

Creating and Running Batch Jobs

A Batch job is a collection of tasks. Follow the steps below to create and run Batch jobs:

Step 1: Create a Job

Create a job that uses the pool created earlier:

az batch job create --id myjob --pool-id mypool

Step 2: Add Tasks to the Job

Add tasks to the job using the following command:

az batch task create --job-id myjob --task-id task1 --command-line "echo Hello World"
az batch task create --job-id myjob --task-id task2 --command-line "echo Azure Batch"

Step 3: Monitor Task Execution

Monitor the execution of tasks using the following command:

az batch task list --job-id myjob --output table
Task ID   State
--------  ------------
task1     Completed
task2     Completed
                    

Cleaning Up Resources

After completing your Batch processing, you should clean up the resources to avoid unnecessary charges. Use the following commands to delete the job, pool, and resource group:

Delete the Job

Run the following command to delete the job:

az batch job delete --job-id myjob

Delete the Pool

Run the following command to delete the pool:

az batch pool delete --pool-id mypool

Delete the Resource Group

Finally, delete the resource group using the following command:

az group delete --name myResourceGroup --yes --no-wait

Conclusion

In this tutorial, we covered the basics of Azure Batch, including setting up a Batch account, creating a Batch pool, and running Batch jobs. Azure Batch is a powerful service that enables you to run large-scale parallel and HPC applications in the cloud efficiently. With Azure Batch, you can scale out your compute resources and only pay for what you use.