Skip to content
Merged
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,15 @@ internal class RebalancerCompatibleRule(IServiceProvider provider) :
private readonly ISiloStatusOracle _oracle = provider.GetRequiredService<ISiloStatusOracle>();
private readonly IActivationRebalancer? _rebalancer = provider.GetService<IActivationRebalancer>();

public bool IsSatisfiedBy(uint imbalance) => imbalance <= _pairwiseImbalance;
public bool IsSatisfiedBy(uint imbalance) => imbalance <= Volatile.Read(ref _pairwiseImbalance);

public void SiloStatusChangeNotification(SiloAddress silo, SiloStatus status)
{
lock (_lock)
{
ref var statusRef = ref CollectionsMarshal.GetValueRefOrAddDefault(_silos, silo, out _);
statusRef = status;

var activeSilos = _silos.Count(s => s.Value == SiloStatus.Active);
var percentageOfBaseline = 100d / (1 + Math.Exp(0.07d * activeSilos - 4.8d));

if (percentageOfBaseline < 10d) percentageOfBaseline = 10d;

var pairwiseImbalance = (uint)Math.Round(10.1d * percentageOfBaseline, 0);
var toleranceFactor = Math.Cos(Math.PI * _clusterImbalance / 2); // This will always be 1 if rebalancer is not registered.

_pairwiseImbalance = (uint)Math.Max(pairwiseImbalance * toleranceFactor, 0);
UpdatePairwiseImbalance();
}
}

Expand All @@ -59,9 +50,23 @@ public void OnReport(RebalancingReport report)
lock (_lock)
{
_clusterImbalance = report.ClusterImbalance;
UpdatePairwiseImbalance();
}
}

private void UpdatePairwiseImbalance()
{
var activeSilos = _silos.Count(s => s.Value == SiloStatus.Active);
var percentageOfBaseline = 100d / (1 + Math.Exp(0.07d * activeSilos - 4.8d));

if (percentageOfBaseline < 10d) percentageOfBaseline = 10d;

var pairwiseImbalance = (uint)Math.Round(10.1d * percentageOfBaseline, 0);
var toleranceFactor = Math.Cos(Math.PI * _clusterImbalance / 2); // This will always be 1 if rebalancer is not registered.

_pairwiseImbalance = (uint)Math.Max(pairwiseImbalance * toleranceFactor, 0);
}

public Task OnStart(CancellationToken cancellationToken)
{
_oracle.SubscribeToSiloStatusEvents(this);
Expand Down