Skip to content

Commit 76955f0

Browse files
committed
minor fixes in weighted algorithm formula
Signed-off-by: Oleh Dokuka <[email protected]>
1 parent dc85fa7 commit 76955f0

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

rsocket-core/src/main/java/io/rsocket/loadbalance/BaseWeightedStats.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ public class BaseWeightedStats implements WeightedStats {
3333
private long stamp0; // last timestamp we sent a request or receive a response
3434
private long duration; // instantaneous cumulative duration
3535

36-
private double availability = 1.0;
37-
3836
private volatile int pendingRequests; // instantaneous rate
3937
private static final AtomicIntegerFieldUpdater<BaseWeightedStats> PENDING_REQUESTS =
4038
AtomicIntegerFieldUpdater.newUpdater(BaseWeightedStats.class, "pendingRequests");
@@ -87,7 +85,7 @@ public double availability() {
8785
if (Clock.now() - stamp > tau) {
8886
updateAvailability(1.0);
8987
}
90-
return availability * availabilityPercentage.value();
88+
return availabilityPercentage.value();
9189
}
9290

9391
@Override
@@ -181,10 +179,6 @@ void updateAvailability(double value) {
181179
}
182180
}
183181

184-
void setAvailability(double availability) {
185-
this.availability = availability;
186-
}
187-
188182
@Override
189183
public String toString() {
190184
return "Stats{"
@@ -215,7 +209,7 @@ public String toString() {
215209
+ ", pendingStreams="
216210
+ pendingStreams
217211
+ ", availability="
218-
+ availability
212+
+ availabilityPercentage.value()
219213
+ '}';
220214
}
221215
}

rsocket-core/src/main/java/io/rsocket/loadbalance/WeightedLoadbalanceStrategy.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ private static double algorithmicWeight(
159159
latency *= calculateFactor(latency, high, bandWidth);
160160
}
161161

162-
return rSocket.availability() / (1.0d + latency * (pending + 1));
162+
return (rSocket.availability() * weightedStats.availability())
163+
/ (1.0d + latency * (pending + 1));
163164
}
164165

165166
private static double calculateFactor(final double u, final double l, final double bandWidth) {

0 commit comments

Comments
 (0)