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

Resource optimized placement strategy #8815

Merged
merged 53 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
a50c16a
wip
Jan 9, 2024
804d767
wip
Jan 10, 2024
737c1ba
added neccessary serives to DefaultSiloServices
Jan 10, 2024
621ccf4
wip
Jan 10, 2024
8990407
.
Jan 10, 2024
76dfc7d
fixing some validations
Jan 10, 2024
2cdbb09
reincoorporated physical ram
Jan 11, 2024
ad4b5c2
some tests for options and validator, and XML docs
Jan 11, 2024
c3831d2
renamed file
Jan 11, 2024
e52ff54
made ResourceOptimizedPlacement strategy public in case users want to…
Jan 11, 2024
aceadec
wip
Jan 9, 2024
7c4cd12
wip
Jan 10, 2024
74d8c87
added neccessary serives to DefaultSiloServices
Jan 10, 2024
e825819
wip
Jan 10, 2024
66a31ec
.
Jan 10, 2024
0a7237c
fixing some validations
Jan 10, 2024
cb774bd
reincoorporated physical ram
Jan 11, 2024
2a0622c
some tests for options and validator, and XML docs
Jan 11, 2024
7ee2a95
renamed file
Jan 11, 2024
8f6d36a
made ResourceOptimizedPlacement strategy public in case users want to…
Jan 11, 2024
599046b
Merge branch 'resource-based-strategy' of https://github.com/ledjon-b…
Jan 11, 2024
32bc695
removed IlocalSiloDetails as there is no need for it
Jan 11, 2024
eac44aa
Merge branch 'main' into merging
Jan 11, 2024
8fce9f8
xml docs
Jan 11, 2024
db27b61
again xml docs
Jan 11, 2024
cc863e0
incoorporated support for avoiding overloaded silos by definition of …
Jan 11, 2024
6ecb31d
Apply suggestions from code review
ReubenBond Jan 12, 2024
018443f
resolving some comments from reviewer
Jan 12, 2024
b056cf2
addressing further comments
Jan 12, 2024
84fb563
PR feedback
ReubenBond Jan 12, 2024
32b1a61
PR feedback
ReubenBond Jan 12, 2024
890ef27
Clean up changes to GetBestSiloCandidate_V2
ReubenBond Jan 12, 2024
fdad669
More tidying
ReubenBond Jan 12, 2024
0300d95
Filter inputs per-silo
ReubenBond Jan 12, 2024
66f0380
More cleanup
ReubenBond Jan 12, 2024
f74edfa
fixed comment
Jan 12, 2024
eb312c1
Merge branch 'resource-based-strategy' of https://github.com/ledjon-b…
Jan 12, 2024
f05a584
more comments
Jan 12, 2024
f85d341
clarify comment
ReubenBond Jan 12, 2024
1c64854
comment on the rational behind using a dual-mode KF as opposed to sin…
Jan 12, 2024
5443eef
Merge branch 'resource-based-strategy' of https://github.com/ledjon-b…
Jan 12, 2024
2799824
some more changes
Jan 12, 2024
053de96
PhysicalMemoryWeight
Jan 12, 2024
eafe948
switched to GetBestSiloCandidate v2
Jan 12, 2024
bd04f77
#
Jan 12, 2024
77414bc
switched to non-generic CDM-KF
Jan 12, 2024
1a1c5aa
Normalize weights & fix LocalSiloPreferenceMargin
ReubenBond Jan 13, 2024
407a7ef
added some comments + fixed _localSiloPreferenceMargin not being set …
Jan 13, 2024
28e3068
rearranged CalculateScore code a bit, and added assertion for score >…
Jan 13, 2024
a807d8a
fix potential for a 'DivideByZeroException'
Jan 13, 2024
965e01e
fixed tests + changed Options class to use int instead of float to ma…
Jan 13, 2024
145c38d
perf improvements
Jan 14, 2024
e707edc
added 'in' modifier to CalculateScore to avoid potential defensive co…
Jan 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,7 @@ public void ValidateConfiguration()
ThrowOutOfRange(nameof(ResourceOptimizedPlacementOptions.LocalSiloPreferenceMargin));
}

if (Truncate(_options.CpuUsageWeight) +
Truncate(_options.MemoryUsageWeight) +
Truncate(_options.AvailableMemoryWeight +
Truncate(_options.PhysicalMemoryWeight)) != 1)
{
throw new OrleansConfigurationException($"The total sum across all the weights of {nameof(ResourceOptimizedPlacementOptions)} must equal 1");
}

static void ThrowOutOfRange(string propertyName)
=> throw new OrleansConfigurationException($"{propertyName} must be inclusive between [0-1]");

static double Truncate(double value)
=> Math.Floor(value * 100) / 100;
}
}
41 changes: 28 additions & 13 deletions src/Orleans.Runtime/Placement/ResourceOptimizedPlacementDirector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ internal sealed class ResourceOptimizedPlacementDirector : IPlacementDirector, I
private const float PhysicalMemoryScalingFactor = 0.00000095367431640625f;
private const int FourKiloByte = 4096;

private readonly ResourceOptimizedPlacementOptions _options;
private readonly NormalizedWeights _options;
private readonly float _localSiloPreferenceMargin;
private readonly ConcurrentDictionary<SiloAddress, FilteredSiloStatistics> _siloStatistics = [];

private Task<SiloAddress> _cachedLocalSilo;
Expand All @@ -29,8 +30,19 @@ internal sealed class ResourceOptimizedPlacementDirector : IPlacementDirector, I
DeploymentLoadPublisher deploymentLoadPublisher,
IOptions<ResourceOptimizedPlacementOptions> options)
{
_options = options.Value;
deploymentLoadPublisher?.SubscribeToStatisticsChangeEvents(this);
_options = NormalizeWeights(options.Value);
deploymentLoadPublisher.SubscribeToStatisticsChangeEvents(this);
}

private static NormalizedWeights NormalizeWeights(ResourceOptimizedPlacementOptions input)
{
var totalWeight = input.CpuUsageWeight + input.MemoryUsageWeight + input.PhysicalMemoryWeight + input.AvailableMemoryWeight;
ledjon-behluli marked this conversation as resolved.
Show resolved Hide resolved

return new (
CpuUsageWeight: input.CpuUsageWeight / totalWeight,
MemoryUsageWeight: input.MemoryUsageWeight / totalWeight,
PhysicalMemoryWeight: input.PhysicalMemoryWeight / totalWeight,
AvailableMemoryWeight: input.AvailableMemoryWeight / totalWeight);
}

public Task<SiloAddress> OnAddActivation(PlacementStrategy strategy, PlacementTarget target, IPlacementContext context)
Expand Down Expand Up @@ -157,18 +169,19 @@ private bool IsLocalSiloPreferable(IPlacementContext context, SiloAddress[] comp
return false;
}

if (_siloStatistics.TryGetValue(context.LocalSilo, out var localStats))
if (!_siloStatistics.TryGetValue(context.LocalSilo, out var local))
{
float localScore = CalculateScore(localStats.Value);
float scoreDiff = Math.Abs(localScore - bestCandidateScore);
return false;
}

if (_options.LocalSiloPreferenceMargin >= scoreDiff)
{
return true;
}
var statistics = local.Value;
if (statistics.IsOverloaded)
{
return false;
}

return false;
var localSiloScore = CalculateScore(statistics);
return localSiloScore - _localSiloPreferenceMargin <= bestCandidateScore;
ledjon-behluli marked this conversation as resolved.
Show resolved Hide resolved
}

/// <summary>
Expand Down Expand Up @@ -240,8 +253,8 @@ public void Update(SiloRuntimeStatistics statistics)
}
}

// The rational behind using a dual-mode KF, is that we want the input signal to follow a trajectory that
// decays with a slower rate than the origianl one, but also tracks the signal in case of signal increases
// The rationale behind using a dual-mode KF, is that we want the input signal to follow a trajectory that
// decays with a slower rate than the original one, but also tracks the signal in case of signal increases
// (which represent potential of overloading). Both are important, but they are inversely correlated to each other.
private sealed class DualModeKalmanFilter
{
Expand Down Expand Up @@ -317,4 +330,6 @@ public float Filter(float measurement, float processNoiseCovariance)
}
}
}

private readonly record struct NormalizedWeights(float CpuUsageWeight, float MemoryUsageWeight, float AvailableMemoryWeight, float PhysicalMemoryWeight);
}