Skip to content

Commit

Permalink
Little more optimized "Solo" startup performance. Closes GH-672
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydmiller committed Jan 2, 2024
1 parent 80e944b commit 85b84e2
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/Persistence/PersistenceTests/Agents/durability_modes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ public async Task start_in_solo_mode()
// Should NOT have a system queue for internal node management messages
runtime.SystemQueue.ShouldBeNull();

// verify that there's a persisted node
// verify that there's NOT a persisted node
var node = await runtime.Storage.Nodes.LoadNodeAsync(runtime.Options.UniqueNodeId, CancellationToken.None);
node.ShouldNotBeNull();
node.ShouldBeNull();

// All agents should be running here
await _host.WaitUntilAssignmentsChangeTo(w =>
Expand Down
88 changes: 88 additions & 0 deletions src/Wolverine/Persistence/Durability/NullMessageStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,92 @@ public Task ReassignIncomingAsync(int ownerId, IReadOnlyList<Envelope> incoming)
{
throw new NotSupportedException();
}
}

internal class NullNodeAgentPersistence : INodeAgentPersistence
{
public Task ClearAllAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}

public Task<int> PersistAsync(WolverineNode node, CancellationToken cancellationToken)
{
return Task.FromResult(0);
}

public Task DeleteAsync(Guid nodeId)
{
return Task.CompletedTask;
}

public Task<IReadOnlyList<WolverineNode>> LoadAllNodesAsync(CancellationToken cancellationToken)
{
return Task.FromResult((IReadOnlyList<WolverineNode>)Array.Empty<WolverineNode>());
}

public Task AssignAgentsAsync(Guid nodeId, IReadOnlyList<Uri> agents, CancellationToken cancellationToken)
{
return Task.CompletedTask;
}

public Task RemoveAssignmentAsync(Guid nodeId, Uri agentUri, CancellationToken cancellationToken)
{
return Task.CompletedTask;
}

public Task AddAssignmentAsync(Guid nodeId, Uri agentUri, CancellationToken cancellationToken)
{
return Task.CompletedTask;
}

public Task<Guid?> MarkNodeAsLeaderAsync(Guid? originalLeader, Guid id)
{
return Task.FromResult(default(Guid?));
}

public Task<Uri?> FindLeaderControlUriAsync(Guid selfId)
{
return Task.FromResult(default(Uri?));
}

public Task<WolverineNode?> LoadNodeAsync(Guid nodeId, CancellationToken cancellationToken)
{
return Task.FromResult(default(WolverineNode?));
}

public Task MarkHealthCheckAsync(Guid nodeId)
{
return Task.CompletedTask;
}

public Task<IReadOnlyList<Uri>> LoadAllOtherNodeControlUrisAsync(Guid selfId)
{
return Task.FromResult((IReadOnlyList<Uri>)Array.Empty<Uri>());
}

public Task<IReadOnlyList<WolverineNode>> LoadAllStaleNodesAsync(DateTimeOffset staleTime, CancellationToken cancellation)
{
return Task.FromResult((IReadOnlyList<WolverineNode>)Array.Empty<WolverineNode>());
}

public Task OverwriteHealthCheckTimeAsync(Guid nodeId, DateTimeOffset lastHeartbeatTime)
{
return Task.CompletedTask;
}

public Task<IReadOnlyList<int>> LoadAllNodeAssignedIdsAsync()
{
return Task.FromResult((IReadOnlyList<int>)Array.Empty<int>());
}

public Task LogRecordsAsync(params NodeRecord[] records)
{
return Task.CompletedTask;
}

public Task<IReadOnlyList<NodeRecord>> FetchRecentRecordsAsync(int count)
{
return Task.FromResult((IReadOnlyList<NodeRecord>)Array.Empty<NodeRecord>());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ public partial class NodeAgentController
{
public async Task StartSoloModeAsync()
{
await _runtime.Storage.Nodes.ClearAllAsync(_cancellation);
await _runtime.Storage.Admin.ReleaseAllOwnershipAsync();

var current = WolverineNode.For(_runtime.Options);

current.AssignedNodeId = await _persistence.PersistAsync(current, _cancellation);
_runtime.Options.Durability.AssignedNodeNumber = current.AssignedNodeId = 1;
await _persistence.LogRecordsAsync(NodeRecord.For(_runtime.Options, NodeRecordType.NodeStarted));

_runtime.Options.Durability.AssignedNodeNumber = current.AssignedNodeId;

foreach (var controller in _agentFamilies.Values)
{
Expand Down
5 changes: 1 addition & 4 deletions src/Wolverine/Runtime/Agents/NodeAgentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,7 @@ public async Task StopAsync(IMessageBus messageBus)
try
{
await _persistence.DeleteAsync(_runtime.Options.UniqueNodeId);
if (_runtime.Options.Durability.Mode == DurabilityMode.Balanced)
{
await _persistence.LogRecordsAsync(NodeRecord.For(_runtime.Options, NodeRecordType.NodeStopped));
}
await _persistence.LogRecordsAsync(NodeRecord.For(_runtime.Options, NodeRecordType.NodeStopped));
}
catch (Exception e)
{
Expand Down
6 changes: 5 additions & 1 deletion src/Wolverine/Runtime/WolverineRuntime.Agents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ private void startDurableScheduledJobs()

private void startNodeAgentController()
{
NodeController = new NodeAgentController(this, Tracker, Storage.Nodes, _container.GetAllInstances<IAgentFamily>(),
INodeAgentPersistence nodePersistence = Options.Durability.Mode == DurabilityMode.Balanced
? Storage.Nodes
: new NullNodeAgentPersistence();

NodeController = new NodeAgentController(this, Tracker, nodePersistence, _container.GetAllInstances<IAgentFamily>(),
LoggerFactory.CreateLogger<NodeAgentController>(), Options.Durability.Cancellation);

NodeController.AddHandlers(this);
Expand Down

0 comments on commit 85b84e2

Please sign in to comment.