Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce Allocation when choosing the Destination #195

Merged
merged 9 commits into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ReverseProxy/Middleware/LoadBalancingMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public Task Invoke(HttpContext context)
return Task.CompletedTask;
}

destinationsFeature.Destinations = new[] { destination };
destinationsFeature.Destinations = destination.Collection;

return _next(context);
}
Expand Down
15 changes: 15 additions & 0 deletions src/ReverseProxy/Service/RuntimeModel/DestinationInfo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Collections.Generic;
using Microsoft.ReverseProxy.Signals;
using Microsoft.ReverseProxy.Utilities;

Expand All @@ -18,6 +19,8 @@ namespace Microsoft.ReverseProxy.RuntimeModel
/// </remarks>
public sealed class DestinationInfo
{
private IReadOnlyList<DestinationInfo> _collection;

public DestinationInfo(string destinationId)
{
Contracts.CheckNonEmpty(destinationId, nameof(destinationId));
Expand All @@ -42,5 +45,17 @@ public DestinationInfo(string destinationId)
/// Keeps track of the total number of concurrent requests on this endpoint.
/// </summary>
public AtomicCounter ConcurrencyCounter { get; } = new AtomicCounter();

internal IReadOnlyList<DestinationInfo> Collection
Kahbazi marked this conversation as resolved.
Show resolved Hide resolved
{
get
{
if (_collection == null)
{
_collection = new[] { this };
Kahbazi marked this conversation as resolved.
Show resolved Hide resolved
}
return _collection;
}
}
}
}