-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8371475: HttpClient: Implement CUBIC congestion controller #28195
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
Open
djelinski
wants to merge
30
commits into
openjdk:master
Choose a base branch
from
djelinski:quic-cubic
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+764
−262
Open
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
dacbb90
Implement packet pacing
djelinski 9478fe6
Less verbose CC logging
djelinski f2393d0
Keep track of pacer-limited events
djelinski be15a20
Fix CRLF
djelinski dab80e5
Fix race in pacer updates, increase low-RTT quota
djelinski 274c13a
Initial cubic commit
djelinski 8e8515b
Implement cubic
djelinski 859b7ab
Log K in milliseconds
djelinski de7ebe9
Cubic tests, more aggressive Reno window increase
djelinski 98e26c3
Documentation updates
djelinski fcd9a71
Use custom timeline for testing
djelinski 2d82033
Test the cubic curve
djelinski 8ecbf0d
Revert: more aggressive window increases
djelinski 060678c
Update test
djelinski f1fdc21
Add comments
djelinski eda81c7
Implement fast convergence
djelinski b95950f
Add a system property to select congestion controller
djelinski 894a394
Rename system property to internal
djelinski fde4d86
Make classes final
djelinski 61c96fe
Merge remote-tracking branch 'origin/master' into quic-cubic
djelinski 74b80eb
More aggressive target growth
djelinski d4e3e60
Merge declaration and assignment
djelinski ff7ecf6
Convert CubicTest to JUnit
djelinski 195b0f8
Update test comments
djelinski 2a1b973
remove useless protected keyword
djelinski 56db950
Refactor QuicBaseCC constructor
djelinski 58708ad
Refactor target calculations
djelinski 32160ef
Add test coverage for Reno
djelinski 2b47732
Add more assertions
djelinski 6068096
Add comment for negative K
djelinski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
318 changes: 318 additions & 0 deletions
318
src/java.net.http/share/classes/jdk/internal/net/http/quic/QuicBaseCongestionController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,318 @@ | ||
| /* | ||
| * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved. | ||
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| * | ||
| * This code is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU General Public License version 2 only, as | ||
| * published by the Free Software Foundation. Oracle designates this | ||
| * particular file as subject to the "Classpath" exception as provided | ||
| * by Oracle in the LICENSE file that accompanied this code. | ||
| * | ||
| * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| * version 2 for more details (a copy is included in the LICENSE file that | ||
| * accompanied this code). | ||
| * | ||
| * You should have received a copy of the GNU General Public License version | ||
| * 2 along with this work; if not, write to the Free Software Foundation, | ||
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| * or visit www.oracle.com if you need additional information or have any | ||
| * questions. | ||
| */ | ||
|
|
||
| package jdk.internal.net.http.quic; | ||
|
|
||
| import jdk.internal.net.http.common.Deadline; | ||
| import jdk.internal.net.http.common.Log; | ||
| import jdk.internal.net.http.common.TimeLine; | ||
| import jdk.internal.net.http.common.TimeSource; | ||
| import jdk.internal.net.http.common.Utils; | ||
| import jdk.internal.net.http.quic.frames.AckFrame; | ||
| import jdk.internal.net.http.quic.packets.QuicPacket; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.concurrent.locks.Lock; | ||
| import java.util.concurrent.locks.ReentrantLock; | ||
|
|
||
| /** | ||
| * Implementation of the common parts of a QUIC congestion controller based on RFC 9002. | ||
| * | ||
| * This class implements the common parts of a congestion controller: | ||
| * - slow start | ||
| * - loss recovery | ||
| * - cooperation with pacer | ||
| * | ||
| * Subclasses implement congestion window growth in congestion avoidance phase. | ||
| * | ||
| * @spec https://www.rfc-editor.org/info/rfc9002 | ||
| * RFC 9002: QUIC Loss Detection and Congestion Control | ||
| */ | ||
| abstract class QuicBaseCongestionController implements QuicCongestionController { | ||
| // higher of 14720 and 2*maxDatagramSize; we use fixed maxDatagramSize | ||
| private static final int INITIAL_WINDOW = Math.max(14720, 2 * QuicConnectionImpl.DEFAULT_DATAGRAM_SIZE); | ||
| private static final int MAX_BYTES_IN_FLIGHT = Math.clamp( | ||
| Utils.getLongProperty("jdk.httpclient.quic.maxBytesInFlight", 1 << 24), | ||
| 1 << 14, 1 << 24); | ||
| final TimeLine timeSource; | ||
| final String dbgTag; | ||
| final Lock lock = new ReentrantLock(); | ||
| long congestionWindow = INITIAL_WINDOW; | ||
| int maxDatagramSize = QuicConnectionImpl.DEFAULT_DATAGRAM_SIZE; | ||
| int minimumWindow = 2 * maxDatagramSize; | ||
| long bytesInFlight; | ||
| // maximum bytes in flight seen since the last congestion event | ||
| long maxBytesInFlight; | ||
| Deadline congestionRecoveryStartTime; | ||
| long ssThresh = Long.MAX_VALUE; | ||
|
|
||
| private final QuicPacer pacer; | ||
|
|
||
| QuicBaseCongestionController(String dbgTag, QuicRttEstimator rttEstimator) { | ||
| this(dbgTag, TimeSource.source(), rttEstimator); | ||
| } | ||
|
|
||
| // Allows to pass a custom timeline for testing | ||
| QuicBaseCongestionController(String dbgTag, TimeLine source, QuicRttEstimator rttEstimator) { | ||
| this.dbgTag = dbgTag; | ||
| this.timeSource = source; | ||
| this.pacer = new QuicPacer(rttEstimator, this); | ||
| } | ||
|
|
||
| boolean inCongestionRecovery(Deadline sentTime) { | ||
| return (congestionRecoveryStartTime != null && | ||
| !sentTime.isAfter(congestionRecoveryStartTime)); | ||
| } | ||
|
|
||
| abstract void onCongestionEvent(Deadline sentTime); | ||
|
|
||
| private static boolean inFlight(QuicPacket packet) { | ||
| // packet is in flight if it contains anything other than a single ACK frame | ||
| // specifically, a packet containing padding is considered to be in flight. | ||
| return packet.frames().size() != 1 || | ||
| !(packet.frames().get(0) instanceof AckFrame); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean canSendPacket() { | ||
| lock.lock(); | ||
| try { | ||
| if (bytesInFlight >= MAX_BYTES_IN_FLIGHT) { | ||
| return false; | ||
| } | ||
| if (isCwndLimited() || isPacerLimited()) { | ||
| return false; | ||
| } | ||
| return true; | ||
| } finally { | ||
| lock.unlock(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void updateMaxDatagramSize(int newSize) { | ||
| lock.lock(); | ||
| try { | ||
| if (minimumWindow != newSize * 2) { | ||
| minimumWindow = newSize * 2; | ||
| maxDatagramSize = newSize; | ||
| congestionWindow = Math.max(congestionWindow, minimumWindow); | ||
| } | ||
| } finally { | ||
| lock.unlock(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void packetSent(int packetBytes) { | ||
| lock.lock(); | ||
| try { | ||
| bytesInFlight += packetBytes; | ||
| if (bytesInFlight > maxBytesInFlight) { | ||
| maxBytesInFlight = bytesInFlight; | ||
| } | ||
| pacer.packetSent(packetBytes); | ||
| } finally { | ||
| lock.unlock(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void packetAcked(int packetBytes, Deadline sentTime) { | ||
| lock.lock(); | ||
| try { | ||
| long oldWindow = congestionWindow; | ||
| assert oldWindow >= minimumWindow : | ||
| "Congestion window lower than minimum: %s < %s".formatted(oldWindow, minimumWindow); | ||
| bytesInFlight -= packetBytes; | ||
| // RFC 9002 says we should not increase cwnd when application limited. | ||
| // The concept itself is poorly defined. | ||
| // Here we limit cwnd growth based on the maximum bytes in flight | ||
| // observed since the last congestion event | ||
| if (inCongestionRecovery(sentTime)) { | ||
| if (Log.quicCC() && Log.trace()) { | ||
| Log.logQuic(dbgTag + " Acked, in recovery: bytes: " + packetBytes + | ||
| ", in flight: " + bytesInFlight); | ||
| } | ||
| return; | ||
| } | ||
| boolean isAppLimited; | ||
| if (congestionWindow < ssThresh) { | ||
| isAppLimited = congestionWindow >= 2 * maxBytesInFlight; | ||
| if (!isAppLimited) { | ||
| congestionWindow += packetBytes; | ||
| } | ||
| } else { | ||
| isAppLimited = congestionAvoidanceAcked(packetBytes, sentTime); | ||
| } | ||
| if (Log.quicCC() && Log.trace()) { | ||
| if (isAppLimited) { | ||
| Log.logQuic(dbgTag + " Acked, not blocked: bytes: " + packetBytes + | ||
| ", in flight: " + bytesInFlight); | ||
| } else { | ||
| Log.logQuic(dbgTag + " Acked, increased: bytes: " + packetBytes + | ||
| ", in flight: " + bytesInFlight + | ||
| ", new cwnd:" + congestionWindow); | ||
| } | ||
| } | ||
| assert congestionWindow >= oldWindow : | ||
| "Window size decreased on ACK: %s to %s".formatted(oldWindow, congestionWindow); | ||
| } finally { | ||
| lock.unlock(); | ||
| } | ||
| } | ||
|
|
||
| abstract boolean congestionAvoidanceAcked(int packetBytes, Deadline sentTime); | ||
|
|
||
| @Override | ||
| public void packetLost(Collection<QuicPacket> lostPackets, Deadline sentTime, boolean persistent) { | ||
| lock.lock(); | ||
| try { | ||
| for (QuicPacket packet : lostPackets) { | ||
| if (inFlight(packet)) { | ||
| bytesInFlight -= packet.size(); | ||
| } | ||
| } | ||
| onCongestionEvent(sentTime); | ||
| if (persistent) { | ||
| congestionWindow = minimumWindow; | ||
| congestionRecoveryStartTime = null; | ||
| if (Log.quicCC()) { | ||
| Log.logQuic(dbgTag + " Persistent congestion: ssThresh: " + ssThresh + | ||
| ", in flight: " + bytesInFlight + | ||
| ", cwnd:" + congestionWindow); | ||
| } | ||
| } | ||
| assert congestionWindow >= minimumWindow : | ||
| "Congestion window lower than minimum: %s < %s".formatted(congestionWindow, minimumWindow); | ||
| } finally { | ||
| lock.unlock(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void packetDiscarded(Collection<QuicPacket> discardedPackets) { | ||
| lock.lock(); | ||
| try { | ||
| for (QuicPacket packet : discardedPackets) { | ||
| if (inFlight(packet)) { | ||
| bytesInFlight -= packet.size(); | ||
| } | ||
| } | ||
| } finally { | ||
| lock.unlock(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public long congestionWindow() { | ||
| lock.lock(); | ||
| try { | ||
| return congestionWindow; | ||
| } finally { | ||
| lock.unlock(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public long initialWindow() { | ||
| lock.lock(); | ||
| try { | ||
| return Math.max(14720, 2 * maxDatagramSize); | ||
| } finally { | ||
| lock.unlock(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public long maxDatagramSize() { | ||
| lock.lock(); | ||
| try { | ||
| return maxDatagramSize; | ||
| } finally { | ||
| lock.unlock(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isSlowStart() { | ||
| lock.lock(); | ||
| try { | ||
| return congestionWindow < ssThresh; | ||
| } finally { | ||
| lock.unlock(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void updatePacer(Deadline now) { | ||
| lock.lock(); | ||
| try { | ||
| pacer.updateQuota(now); | ||
| } finally { | ||
| lock.unlock(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isPacerLimited() { | ||
| lock.lock(); | ||
| try { | ||
| return !pacer.canSend(); | ||
| } finally { | ||
| lock.unlock(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isCwndLimited() { | ||
| lock.lock(); | ||
| try { | ||
| return congestionWindow - bytesInFlight < maxDatagramSize; | ||
| } finally { | ||
| lock.unlock(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public Deadline pacerDeadline() { | ||
| lock.lock(); | ||
| try { | ||
| return pacer.twoPacketDeadline(); | ||
| } finally { | ||
| lock.unlock(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void appLimited() { | ||
| lock.lock(); | ||
| try { | ||
| pacer.appLimited(); | ||
| } finally { | ||
| lock.unlock(); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.