Skip to content

Commit 21c6227

Browse files
Update sample projects to support variable slots scheduling (#293)
* Update sample projects to support variable slots scheduling * Refactor task slots per task and add it into output * Bump Microsoft.Azure.Batch package to 14.0.0
1 parent ff3dcdc commit 21c6227

File tree

27 files changed

+137
-52
lines changed

27 files changed

+137
-52
lines changed

CSharp/ArticleProjects/ApplicationInsights/TopNWords/TopNWords.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
<ProjectReference Include="..\..\..\Common\Microsoft.Azure.Batch.Samples.Common.csproj" />
1111
<ProjectReference Include="..\Microsoft.Azure.Batch.Samples.TelemetryInitializer\Microsoft.Azure.Batch.Samples.TelemetryInitializer.csproj" />
1212
<ProjectReference Include="..\Microsoft.Azure.Batch.Samples.TelemetryStartTask\Microsoft.Azure.Batch.Samples.TelemetryStartTask.csproj" />
13-
13+
1414
</ItemGroup>
1515

1616
<ItemGroup>
17-
<PackageReference Include="Microsoft.Azure.Batch" Version="12.0.0" />
17+
<PackageReference Include="Microsoft.Azure.Batch" Version="14.0.0" />
1818
<PackageReference Include="Microsoft.Azure.Batch.FileStaging" Version="8.3.0" />
1919
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="2.1.0" />
2020
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.0" />

CSharp/ArticleProjects/EfficientListQueries/EfficientListQueries.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</ItemGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.Azure.Batch" Version="12.0.0" />
14+
<PackageReference Include="Microsoft.Azure.Batch" Version="14.0.0" />
1515
</ItemGroup>
1616

1717
</Project>

CSharp/ArticleProjects/EfficientListQueries/Program.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private static async Task MainAsync(string[] args)
4747
// You may adjust these values to experiment with different compute resource scenarios.
4848
const string nodeSize = "standard_d1_v2";
4949
const int nodeCount = 1;
50-
const int maxTasksPerNode = 4;
50+
const int taskSlotsPerNode = 4;
5151

5252
// Adjust the task count to experiment with different list operation query durations
5353
const int taskCount = 5000;
@@ -72,8 +72,8 @@ private static async Task MainAsync(string[] args)
7272
poolId,
7373
nodeSize,
7474
nodeCount,
75-
maxTasksPerNode);
76-
75+
taskSlotsPerNode);
76+
7777
// Create a CloudJob, or obtain an existing job with the specified ID
7878
CloudJob job = await ArticleHelpers.CreateJobIfNotExistAsync(batchClient, poolId, jobId);
7979

@@ -190,9 +190,9 @@ private static async Task QueryTasksAsync(BatchClient batchClient, string jobId,
190190
Stopwatch stopwatch = Stopwatch.StartNew();
191191

192192
taskList.AddRange(await batchClient.JobOperations.ListTasks(jobId, detail).ToListAsync());
193-
193+
194194
stopwatch.Stop();
195-
195+
196196
Console.WriteLine("{0} tasks retrieved in {1} (ExpandClause: {2} | FilterClause: {3} | SelectClause: {4})",
197197
taskList.Count,
198198
stopwatch.Elapsed,

CSharp/ArticleProjects/JobPrepRelease/JobPrepRelease.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</ItemGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.Azure.Batch" Version="12.0.0" />
14+
<PackageReference Include="Microsoft.Azure.Batch" Version="14.0.0" />
1515
</ItemGroup>
1616

1717
</Project>

CSharp/ArticleProjects/MultiInstanceTasks/MultiInstanceTasks.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
</ItemGroup>
2424

2525
<ItemGroup>
26-
<PackageReference Include="Microsoft.Azure.Batch" Version="12.0.0" />
26+
<PackageReference Include="Microsoft.Azure.Batch" Version="14.0.0" />
2727
<PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />
2828
</ItemGroup>
2929

CSharp/ArticleProjects/MultiInstanceTasks/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static void Main(string[] args)
3939
Console.ReadLine();
4040
}
4141
}
42-
42+
4343
public static async Task MainAsync()
4444
{
4545
const string poolId = "MultiInstanceSamplePool";
@@ -206,7 +206,7 @@ private static async Task CreatePoolAsync(BatchClient batchClient, string poolId
206206
// sample, MPIHelloWorld.exe) running on the different nodes
207207
unboundPool.InterComputeNodeCommunicationEnabled = true;
208208
// REQUIRED for multi-instance tasks
209-
unboundPool.MaxTasksPerComputeNode = 1;
209+
unboundPool.TaskSlotsPerNode = 1;
210210

211211
// Specify the application and version to deploy to the compute nodes.
212212
unboundPool.ApplicationPackageReferences = new List<ApplicationPackageReference>

CSharp/ArticleProjects/ParallelTasks/ParallelTasks.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</ItemGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.Azure.Batch" Version="12.0.0" />
14+
<PackageReference Include="Microsoft.Azure.Batch" Version="14.0.0" />
1515
</ItemGroup>
1616

1717
</Project>

CSharp/ArticleProjects/ParallelTasks/Program.cs

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ public static void Main(string[] args)
4545
private static async Task MainAsync(string[] args)
4646
{
4747
// You may adjust these values to experiment with different compute resource scenarios.
48-
const string nodeSize = "standard_d1_v2";
49-
const int nodeCount = 4;
50-
const int maxTasksPerNode = 4;
51-
const int taskCount = 32;
48+
const string nodeSize = "standard_d1_v2";
49+
const int nodeCount = 4;
50+
const int taskSlotsPerNode = 4;
51+
const int taskCount = 32;
5252

5353
// Ensure there are enough tasks to help avoid hitting some timeout conditions below
54-
int minimumTaskCount = nodeCount * maxTasksPerNode * 2;
54+
int minimumTaskCount = nodeCount * taskSlotsPerNode * 2;
5555
if (taskCount < minimumTaskCount)
5656
{
5757
Console.WriteLine("You must specify at least two tasks per node core for this sample ({0} tasks in this configuration).", minimumTaskCount);
@@ -61,6 +61,18 @@ private static async Task MainAsync(string[] args)
6161
return;
6262
}
6363

64+
// In this sample, each task is assigned with random required slots; adjust these values
65+
// to simulate variable task slots together with allowed task slots per compute node
66+
const int maxTaskSlots = 2;
67+
if (maxTaskSlots > taskSlotsPerNode)
68+
{
69+
Console.WriteLine("Invalid task slot configuration: maxTaskSlots for task should not be greater than pool's TaskSlotsPerNode");
70+
Console.WriteLine();
71+
72+
// Invalid task slot configuration, exit the application
73+
return;
74+
}
75+
6476
// In this sample, the tasks simply ping localhost on the compute nodes; adjust these
6577
// values to simulate variable task duration
6678
const int minPings = 30;
@@ -89,7 +101,7 @@ private static async Task MainAsync(string[] args)
89101
poolId,
90102
nodeSize,
91103
nodeCount,
92-
maxTasksPerNode);
104+
taskSlotsPerNode);
93105

94106
// Create a CloudJob, or obtain an existing pool with the specified ID
95107
CloudJob job = await ArticleHelpers.CreateJobIfNotExistAsync(batchClient, poolId, jobId);
@@ -102,7 +114,10 @@ private static async Task MainAsync(string[] args)
102114
{
103115
string taskId = "task" + i.ToString().PadLeft(3, '0');
104116
string taskCommandLine = "ping -n " + rand.Next(minPings, maxPings + 1).ToString() + " localhost";
105-
CloudTask task = new CloudTask(taskId, taskCommandLine);
117+
CloudTask task = new CloudTask(taskId, taskCommandLine)
118+
{
119+
RequiredSlots = rand.Next(1, maxTaskSlots + 1)
120+
};
106121
tasks.Add(task);
107122
}
108123

@@ -129,6 +144,18 @@ private static async Task MainAsync(string[] args)
129144
await GettingStartedCommon.PrintNodeTasksAsync(batchClient, pool.Id);
130145
Console.WriteLine();
131146

147+
// Print out running task and task slot counts on all nodes.
148+
Console.WriteLine();
149+
await GettingStartedCommon.PrintNodeTaskCountsAsync(batchClient, pool.Id);
150+
Console.WriteLine();
151+
152+
// Print out task and task slot counts of the job.
153+
// Note: it may have delay as Batch service is aggregating task counts for the job.
154+
await Task.Delay(TimeSpan.FromSeconds(5));
155+
Console.WriteLine();
156+
await GettingStartedCommon.PrintJobTaskCountsAsync(batchClient, jobId);
157+
Console.WriteLine();
158+
132159
// Pause execution while we wait for all of the tasks to complete
133160
Console.WriteLine("Waiting for task completion...");
134161
Console.WriteLine();
@@ -147,10 +174,16 @@ await batchClient.Utilities.CreateTaskStateMonitor().WhenAll(
147174

148175
stopwatch.Stop();
149176

177+
// Print out job task counts again.
178+
await Task.Delay(TimeSpan.FromSeconds(5));
179+
Console.WriteLine();
180+
await GettingStartedCommon.PrintJobTaskCountsAsync(batchClient, jobId);
181+
Console.WriteLine();
182+
150183
// Obtain the tasks, specifying a detail level to limit the number of properties returned for each task.
151184
// If you have a large number of tasks, specifying a DetailLevel is extremely important in reducing the
152185
// amount of data transferred, lowering your query response times in increasing performance.
153-
ODATADetailLevel detail = new ODATADetailLevel(selectClause: "id,commandLine,nodeInfo,state");
186+
ODATADetailLevel detail = new ODATADetailLevel(selectClause: "id,commandLine,nodeInfo,state,requiredSlots");
154187
IPagedEnumerable<CloudTask> allTasks = batchClient.JobOperations.ListTasks(job.Id, detail);
155188

156189
// Get a collection of the completed tasks sorted by the compute nodes on which they executed
@@ -173,7 +206,7 @@ await batchClient.Utilities.CreateTaskStateMonitor().WhenAll(
173206

174207
lastNodeId = task.ComputeNodeInformation.ComputeNodeId;
175208

176-
Console.WriteLine("\t{0}: {1}", task.Id, task.CommandLine);
209+
Console.WriteLine($"\t{task.Id} (slots={task.RequiredSlots}): {task.CommandLine}");
177210
}
178211

179212
// Get a collection of the uncompleted tasks which may exist if the TaskMonitor timeout was hit
@@ -200,11 +233,12 @@ await batchClient.Utilities.CreateTaskStateMonitor().WhenAll(
200233

201234
// Print some summary information
202235
Console.WriteLine();
203-
Console.WriteLine(" Nodes: " + nodeCount);
204-
Console.WriteLine(" Node size: " + nodeSize);
205-
Console.WriteLine("Max tasks per node: " + pool.MaxTasksPerComputeNode);
206-
Console.WriteLine(" Tasks: " + tasks.Count);
207-
Console.WriteLine(" Duration: " + stopwatch.Elapsed);
236+
Console.WriteLine(" Nodes: " + nodeCount);
237+
Console.WriteLine(" Node size: " + nodeSize);
238+
Console.WriteLine("Task slots per node: " + pool.TaskSlotsPerNode);
239+
Console.WriteLine(" Max slots per task: " + maxTaskSlots);
240+
Console.WriteLine(" Tasks: " + tasks.Count);
241+
Console.WriteLine(" Duration: " + stopwatch.Elapsed);
208242
Console.WriteLine();
209243
Console.WriteLine("Done!");
210244
Console.WriteLine();
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
### ParallelTasks
22

3-
This console application sample project backs the code snippets found in [Maximize Azure Batch compute resource usage with concurrent node tasks](http://azure.microsoft.com/documentation/articles/batch-parallel-node-tasks/). The application demonstrates the creation of a Batch pool whose compute nodes are configured for executing multiple concurrent tasks, and prints node and task information to the console during execution to show how tasks are distributed among compute nodes and node cores.
3+
This console application sample project backs the code snippets found in [Maximize Azure Batch compute resource usage with concurrent node tasks](http://azure.microsoft.com/documentation/articles/batch-parallel-node-tasks/). The application demonstrates the creation of a Batch pool whose compute nodes are configured for executing multiple concurrent tasks, submit tasks with variable slots, and prints node/job/task information to the console during execution to show how tasks are distributed among compute nodes and node cores.
4+
5+
1. Open the project in **Visual Studio 2017**.
6+
2. Add your Batch and Storage **account credentials** to **accountsettings.json** in the Microsoft.Azure.Batch.Samples.Common project.
7+
3. **Build** and then **run** the solution. Restore any NuGet packages if prompted.

CSharp/ArticleProjects/PersistOutputs/PersistOutputs.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
</ItemGroup>
1818

1919
<ItemGroup>
20-
<PackageReference Include="Microsoft.Azure.Batch" Version="12.0.0" />
20+
<PackageReference Include="Microsoft.Azure.Batch" Version="14.0.0" />
2121
<PackageReference Include="Microsoft.Azure.Batch.Conventions.Files" Version="3.5.1" />
22-
22+
2323
</ItemGroup>
2424

2525
</Project>

0 commit comments

Comments
 (0)