From d53449a9abe17e24a667cbac5a5e1dfec37fb498 Mon Sep 17 00:00:00 2001 From: Sebastian Burckhardt Date: Wed, 25 May 2022 11:35:58 -0700 Subject: [PATCH] generalize placement for instance id. (#159) --- .../NetheriteOrchestrationService.cs | 10 ++++++---- .../CollisionSearch/DivideAndConquerSearch.cs | 2 +- .../Benchmarks/Counter/HttpTriggers.cs | 2 +- test/PerformanceTests/Benchmarks/WordCount/Mapper.cs | 2 +- test/PerformanceTests/Benchmarks/WordCount/Reducer.cs | 2 +- test/PerformanceTests/Common/ManyOrchestrations.cs | 2 +- test/PerformanceTests/Common/Ping.cs | 2 +- 7 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/DurableTask.Netherite/OrchestrationService/NetheriteOrchestrationService.cs b/src/DurableTask.Netherite/OrchestrationService/NetheriteOrchestrationService.cs index 0b7b276d..0999fe79 100644 --- a/src/DurableTask.Netherite/OrchestrationService/NetheriteOrchestrationService.cs +++ b/src/DurableTask.Netherite/OrchestrationService/NetheriteOrchestrationService.cs @@ -517,12 +517,14 @@ async Task TryStopAsync(bool quickly) /// The partition id. public uint GetPartitionId(string instanceId) { + int placementSeparatorPosition = instanceId.LastIndexOf('!'); + // if the instance id ends with !nn, where nn is a two-digit number, it indicates explicit partition placement - if (instanceId.Length >= 3 - && instanceId[instanceId.Length - 3] == '!' - && uint.TryParse(instanceId.Substring(instanceId.Length - 2), out uint nn)) + if (placementSeparatorPosition != -1 + && placementSeparatorPosition <= instanceId.Length - 2 + && uint.TryParse(instanceId.Substring(placementSeparatorPosition + 1), out uint index)) { - var partitionId = nn % this.NumberPartitions; + var partitionId = index % this.NumberPartitions; //this.Logger.LogTrace($"Instance: {instanceId} was explicitly placed on partition: {partitionId}"); return partitionId; } diff --git a/test/PerformanceTests/Benchmarks/CollisionSearch/DivideAndConquerSearch.cs b/test/PerformanceTests/Benchmarks/CollisionSearch/DivideAndConquerSearch.cs index cfa73bde..f2e1a684 100644 --- a/test/PerformanceTests/Benchmarks/CollisionSearch/DivideAndConquerSearch.cs +++ b/test/PerformanceTests/Benchmarks/CollisionSearch/DivideAndConquerSearch.cs @@ -43,7 +43,7 @@ public static async Task> Run([OrchestrationTrigger] IDurableOrchestr { subOrchestratorTasks[i] = context.CallSubOrchestratorAsync>( nameof(DivideAndConquerSearch), - // $"{context.InstanceId}!{i:D2}", + // $"{context.InstanceId}!{i}", new IntervalSearchParameters() { Target = input.Target, diff --git a/test/PerformanceTests/Benchmarks/Counter/HttpTriggers.cs b/test/PerformanceTests/Benchmarks/Counter/HttpTriggers.cs index a39730f3..fee4990c 100644 --- a/test/PerformanceTests/Benchmarks/Counter/HttpTriggers.cs +++ b/test/PerformanceTests/Benchmarks/Counter/HttpTriggers.cs @@ -123,7 +123,7 @@ public static async Task CountParallelSignals( int numberSignals = int.Parse(input.Substring(0, commaPosition)); int numberEntities = int.Parse(input.Substring(commaPosition + 1)); var entityPrefix = Guid.NewGuid().ToString("N"); - EntityId MakeEntityId(int i) => new EntityId("Counter", $"{entityPrefix}-{i/100:D6}!{i%100:D2}"); + EntityId MakeEntityId(int i) => new EntityId("Counter", $"{entityPrefix}-!{i:D6}"); DateTime startTime = DateTime.UtcNow; if (numberSignals % numberEntities != 0) diff --git a/test/PerformanceTests/Benchmarks/WordCount/Mapper.cs b/test/PerformanceTests/Benchmarks/WordCount/Mapper.cs index 9ad9b1ef..8009b088 100644 --- a/test/PerformanceTests/Benchmarks/WordCount/Mapper.cs +++ b/test/PerformanceTests/Benchmarks/WordCount/Mapper.cs @@ -28,7 +28,7 @@ public enum Ops public static EntityId GetEntityId(int number) { - return new EntityId(nameof(Mapper), $"{number}!{number % 100:D2}"); + return new EntityId(nameof(Mapper), $"!{number}"); } [FunctionName(nameof(Mapper))] diff --git a/test/PerformanceTests/Benchmarks/WordCount/Reducer.cs b/test/PerformanceTests/Benchmarks/WordCount/Reducer.cs index 45329fdf..834a673f 100644 --- a/test/PerformanceTests/Benchmarks/WordCount/Reducer.cs +++ b/test/PerformanceTests/Benchmarks/WordCount/Reducer.cs @@ -15,7 +15,7 @@ public static class Reducer { public static EntityId GetEntityId(int number) { - return new EntityId(nameof(Reducer), $"{number}!{number % 100:D2}"); + return new EntityId(nameof(Reducer), $"!{number}"); } public enum Ops diff --git a/test/PerformanceTests/Common/ManyOrchestrations.cs b/test/PerformanceTests/Common/ManyOrchestrations.cs index 2b64112a..ee32e441 100644 --- a/test/PerformanceTests/Common/ManyOrchestrations.cs +++ b/test/PerformanceTests/Common/ManyOrchestrations.cs @@ -107,7 +107,7 @@ await Enumerable.Range(0, numberOrchestrations).ParallelForEachAsync(200, true, while (pos < numberOrchestrations) { int portion = Math.Min(portionSize.Value, (numberOrchestrations - pos)); - var entityId = new EntityId(nameof(LauncherEntity), $"launcher{launcher / 100:D6}!{launcher % 100:D2}"); + var entityId = new EntityId(nameof(LauncherEntity), $"launcher!{launcher:D6}"); tasks.Add(client.SignalEntityAsync(entityId, nameof(LauncherEntity.Launch), (orchestrationName, prefix, portion, pos, input))); pos += portion; launcher++; diff --git a/test/PerformanceTests/Common/Ping.cs b/test/PerformanceTests/Common/Ping.cs index 2381369f..3e1a5e22 100644 --- a/test/PerformanceTests/Common/Ping.cs +++ b/test/PerformanceTests/Common/Ping.cs @@ -43,7 +43,7 @@ public static async Task Run( async Task Ping(int partition) { - string instanceId = $"ping!{partition:D2}"; + string instanceId = $"ping!{partition}"; var timeoutTask = Task.Delay(timeout); var startTask = client.StartNewAsync(nameof(Pingee), instanceId);