Skip to content

Commit

Permalink
generalize placement for instance id. (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianburckhardt authored May 25, 2022
1 parent d18ba2c commit d53449a
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -517,12 +517,14 @@ async Task<ServiceState> TryStopAsync(bool quickly)
/// <returns>The partition id.</returns>
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static async Task<List<long>> Run([OrchestrationTrigger] IDurableOrchestr
{
subOrchestratorTasks[i] = context.CallSubOrchestratorAsync<List<long>>(
nameof(DivideAndConquerSearch),
// $"{context.InstanceId}!{i:D2}",
// $"{context.InstanceId}!{i}",
new IntervalSearchParameters()
{
Target = input.Target,
Expand Down
2 changes: 1 addition & 1 deletion test/PerformanceTests/Benchmarks/Counter/HttpTriggers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public static async Task<IActionResult> 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)
Expand Down
2 changes: 1 addition & 1 deletion test/PerformanceTests/Benchmarks/WordCount/Mapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down
2 changes: 1 addition & 1 deletion test/PerformanceTests/Benchmarks/WordCount/Reducer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/PerformanceTests/Common/ManyOrchestrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down
2 changes: 1 addition & 1 deletion test/PerformanceTests/Common/Ping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static async Task<IActionResult> Run(

async Task<string> Ping(int partition)
{
string instanceId = $"ping!{partition:D2}";
string instanceId = $"ping!{partition}";

var timeoutTask = Task.Delay(timeout);
var startTask = client.StartNewAsync(nameof(Pingee), instanceId);
Expand Down

0 comments on commit d53449a

Please sign in to comment.