Use bytesReceived instead of decreasing multiplicatively
This commit is contained in:
+15
-22
@@ -10,26 +10,29 @@ import java.util.function.IntSupplier;
|
|||||||
public class ClientCongestionControl
|
public class ClientCongestionControl
|
||||||
{
|
{
|
||||||
private static final double ADDITIVE_INCREASE = 50000;
|
private static final double ADDITIVE_INCREASE = 50000;
|
||||||
private static final double MULTIPLICATIVE_DECREASE = 0.75;
|
|
||||||
private static final long INTERVAL_MS = 1000;
|
private static final long INTERVAL_MS = 1000;
|
||||||
|
|
||||||
private final AtomicLong bytesReceived = new AtomicLong(0);
|
|
||||||
private volatile double lastIntervalThroughput = 0;
|
|
||||||
|
|
||||||
private double desiredRate = 50000;
|
|
||||||
private long lastAdjustTime = System.currentTimeMillis();
|
|
||||||
|
|
||||||
private final IntSupplier currentRateSupplier;
|
|
||||||
private final Runnable rateUpdateHandler;
|
private final Runnable rateUpdateHandler;
|
||||||
|
|
||||||
|
private final AtomicLong bytesReceived = new AtomicLong(0);
|
||||||
|
|
||||||
|
private double desiredRate;
|
||||||
|
private long lastAdjustTime;
|
||||||
|
|
||||||
|
|
||||||
public ClientCongestionControl(
|
public ClientCongestionControl(
|
||||||
IntSupplier currentRateSupplier,
|
|
||||||
Runnable rateUpdateHandler
|
Runnable rateUpdateHandler
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
this.currentRateSupplier = currentRateSupplier;
|
|
||||||
this.rateUpdateHandler = rateUpdateHandler;
|
this.rateUpdateHandler = rateUpdateHandler;
|
||||||
|
this.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reset()
|
||||||
|
{
|
||||||
|
this.desiredRate = ADDITIVE_INCREASE;
|
||||||
|
this.lastAdjustTime = System.currentTimeMillis();
|
||||||
|
this.bytesReceived.set(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -46,27 +49,17 @@ public class ClientCongestionControl
|
|||||||
|
|
||||||
private void adjustRate(long now)
|
private void adjustRate(long now)
|
||||||
{
|
{
|
||||||
this.desiredRate = this.currentRateSupplier.getAsInt() * 1000;
|
|
||||||
double throughput = this.bytesReceived.getAndSet(0);
|
double throughput = this.bytesReceived.getAndSet(0);
|
||||||
|
if (throughput >= this.desiredRate)
|
||||||
if (throughput != 0 && throughput >= this.lastIntervalThroughput)
|
|
||||||
{
|
{
|
||||||
this.desiredRate += ADDITIVE_INCREASE;
|
this.desiredRate += ADDITIVE_INCREASE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.desiredRate *= MULTIPLICATIVE_DECREASE;
|
this.desiredRate = Math.max(throughput - ADDITIVE_INCREASE / 2, 1000);
|
||||||
throughput *= MULTIPLICATIVE_DECREASE;
|
|
||||||
|
|
||||||
if (this.desiredRate < 1)
|
|
||||||
{
|
|
||||||
this.desiredRate = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.lastIntervalThroughput = throughput;
|
|
||||||
this.lastAdjustTime = now;
|
this.lastAdjustTime = now;
|
||||||
|
|
||||||
this.rateUpdateHandler.run();
|
this.rateUpdateHandler.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
-2
@@ -58,7 +58,6 @@ public class ClientNetworkState implements Closeable
|
|||||||
public long getServerTimeOffset() { return this.serverTimeOffset; }
|
public long getServerTimeOffset() { return this.serverTimeOffset; }
|
||||||
|
|
||||||
private final ClientCongestionControl congestionControl = new ClientCongestionControl(
|
private final ClientCongestionControl congestionControl = new ClientCongestionControl(
|
||||||
() -> this.sessionConfig.getMaxDataTransferSpeed(),
|
|
||||||
() -> {
|
() -> {
|
||||||
if (Config.Server.enableAdaptiveTransferSpeed.get())
|
if (Config.Server.enableAdaptiveTransferSpeed.get())
|
||||||
{
|
{
|
||||||
@@ -66,7 +65,14 @@ public class ClientNetworkState implements Closeable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
private final ConfigChangeListener<Boolean> adaptiveTransferSpeedListener = new ConfigChangeListener<>(Config.Server.enableAdaptiveTransferSpeed, this::sendConfigMessage);
|
private final ConfigChangeListener<Boolean> adaptiveTransferSpeedListener = new ConfigChangeListener<>(Config.Server.enableAdaptiveTransferSpeed, isEnabled -> {
|
||||||
|
if (isEnabled)
|
||||||
|
{
|
||||||
|
this.congestionControl.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.sendConfigMessage();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user