What is Azure Batch and When Should I Use It? Introduction

5 Jan 2022
|
6 min read
Behind The Code

This article will give you a brief overview of what Azure Batch is, what it can be used for, and provide a few definitions to give you solid fundamentals before going into details. In the future second part, I will provide you with some production running examples with shortcode snippets which will give you a good start before writing your own applications.

So let’s dive into the world of Azure Batch.

What is Azure Batch?

Azure Batch is part of the Azure cloud offer by Microsoft. Let’s see what the official documentation has to say:

Source: Microsoft

Azure Batch is a compute management platform from Azure that allows for large-scale parallel batch workloads to be run in the cloud.”

The Azure Batch platform is designed to run custom batch computing jobs across any number of scalable nodes (Virtual Machines). It’s a perfect fit for cases when a high CPU/memory demanding process can be executed in multiple parallel tasks which are independent of each other.

Some examples of workloads that you can perform in Batch:

  • Image processing and rendering
  • Engineering Simulations
  • Deep Learning
  • ETL (extract-transform-load procedure)
  • Software tests execution

Need Azure Batch experts?

We can discuss and set up your project.

Contact us

Azure Batch Definitions – What You Need to Know to Start

First of all, you have to initialize an Azure Batch component in Azure, then you will be able to create compute nodes and pools.

Azure Batch Concepts

Let’s understand some of these concepts used by Azure Batch.

Azure Batch Node – A node is a single Azure VM that processes a chunk of your workload in Azure Batch. You can choose the size of the node, which determines the number of CPU cores and memory capacity. Nodes can run on either Windows/Linux system or any custom image. Nodes are able to run any executable or script which is supported by the installed system environment.

Azure Batch Pool – A compute pool is a collection of nodes that your application is running on. It’s the top component of an Azure Batch platform and it provides allocation, flexible scaling number of nodes, installation of applications on the nodes, data distribution, and monitoring.

Assigning Work – Jobs and Tasks

When the pool and node setups are done we can assign work to them. A workload is in the format of a job and a task.

Azure Batch Job – a collection of tasks. It manages how the execution is performed by tasks on compute nodes.

Azure Batch Task – single execution of the job running on the node. They are assigned for specified nodes or queued if the node is taken. From a technical point of view, the task just runs one or more programs or scripts previously uploaded to the node.

Creating a Task

While creating a task you can specify:

  • Command line. This is a command which runs your program or script on the node. For example:
    ./MyApplication param1 param2
  • Resource files. It can contain data to be processed. It’s copied from Blob storage before execution of the command line.
  • Environment variables
  • Constraints. For example, they can determine the maximal execution time or the number of retries in case of failure.

The Start Task

The Start task is a special kind of task that is run on the node before the computation is executed. For example, you can use it to perform the installation of necessary software, fetch data, start background processes, etc.

Start tasks run after the node starts or when it is restarted or reimaged. If a start task fails (for example if a non-zero status code is returned), the node status is updated and does not execute further tasks.


How Does Azure Batch Work?

The diagram below shows casual steps to perform workload on Azure Batch.

Source: Microsoft

1. Upload input files and apps

Input files can be any data you want to process. Data can be also fetched from any other source: database, external API, etc. For the application, you can upload executables, scripts, or installers of programs that will process the data.

2. Create pool, job, tasks

As previously described, nodes are VMs that run your tasks. At this point, you have to choose the number, size, and operating system or image of nodes. Then you have to create jobs and assign tasks to them. Each task will run the application on the first step.

3. Download resources 

Before each task begins executing, it downloads input data to its own file system and downloads the script or application if it’s not already on the node. When the download and start task (if defined) is complete, the task processes its workload.

4. Monitor task execution

Execution of the tasks can be monitored from your service by using HTTP calls or custom Application Insights implementation. You can also monitor the whole process on the visual interface in the Azure portal.

5. Upload task output

When the task finishes its work, it uploads the result data to Azure Storage (or any other destination). The result can be also directly obtained from the node file system.

6. Download output files

When your services detect that tasks are finished, results can be downloaded from Azure Storage (or any other source).

The workflow above is just an example of how to use Batch. Since Azure Batch is just kind of an orchestrator for executing parallel workloads on VMs, you can adjust the whole process to your demands.

Virtual Machines Sizes and Pricing

When selecting a node size for a pool you can choose from almost all the VM sizes available in Azure both for Linux and Windows. Supported VM size might depend on the Azure region. You only pay for the time when the Batch pool is created – you also pay when it’s idle. To optimize costs it’s recommended to delete the pool after work is done.

It makes Azure Batch really convenient and cost-effective when you need to perform high-demand for resources for a short period of time – you only pay for the execution time. 

For more details visit https://azure.microsoft.com/en-us/pricing/details/batch/.


Should I Use Azure Batch?

Let’s check the pros and cons:

Pros of Azure Batch

  1. Cost-effective – with proper pool management you only pay for the time the workload is executed. 
  2. Elastic – you can easily match VM configuration and workflow to your demands. You can choose from general usage A-tier to N-tier VMs with hundreds of RAM memory and dozens of processors.

Cons of Azure Batch

  1. Complex – Azure Batch system might be difficult to manage. Setting up the whole system: pools, jobs, and tasks might be confusing for beginners and it needs some experience to make Azure batch reliable and cost-effective.
  2. Limited support – Lack of in-depth documentation and poor developer support. As Azure Batch is still strongly developed by Microsoft and the service is used mostly by big companies, it did not live to see thorough documentation and community support yet.

Summary – Azure Batch Introduction

Azure Batch might be a powerful tool in your toolkit. It can help you reduce execution time on your high-demand workloads with great cost optimization. Since the solution is based on Azure VMs it makes Azure Batch really flexible and gives you full control over the whole process.

It was the first part of a two-article series covering Azure Batch. The second part will be much more technical and we will dive into the real-life implementation of the whole flow. 

Azure
Cloud
Snippet

Written by