TCP: Coalesce more ACKs in DelayedAcknowledge.

First, we don't need to generate ACKs for every other
segment received, only every second full-size segment
or within 500ms, as the comment notes. So check the
receive window size before deciding to send an ACK
immediately.

Second, let the timeout routine handle sending the ACK
even in the immediate invocation case. This way, we
don't spend time in receive routines waiting for the
send path locks, and also multiple packets received in
quick succession will have one ACK generated instead of
many.

Also, following the previous commit, the timeout routine
will avoid generating duplicate ACKs now. In the case
where a duplicate ACK really needs to be generated,
DelayedAcknowledge won't be used anyway.

Inspired by ambroff's remarks and patch in
comment:14 of #18203.

Greatly reduces the number of ACKs generated,
and increases throughput due to less duplicate ACKs
causing congestion logic to kick in.

Change-Id: I37991464b1a802aceb3e2b453df8dc4cb2e14ce5
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7284
Reviewed-by: Alex von Gluck IV <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
Augustin Cavalier
2023-12-31 03:36:27 +00:00
committed by waddlesplash
parent 5e7d399ef4
commit d7c71d7b49
@@ -1134,15 +1134,19 @@ TCPEndpoint::IsLocal() const
status_t status_t
TCPEndpoint::DelayedAcknowledge() TCPEndpoint::DelayedAcknowledge()
{ {
if (gStackModule->cancel_timer(&fDelayedAcknowledgeTimer)) { // ACKs "MUST" be generated within 500ms of the first unACKed packet, and
// timer was active, send an ACK now (with the exception above, // "SHOULD" be for at least every second full-size segment. (RFC 5681 § 4.2)
// we send every other ACK)
T(TimerSet(this, "delayed ack", -1)); bigtime_t delay = TCP_DELAYED_ACKNOWLEDGE_TIMEOUT;
return SendAcknowledge(true); if ((fReceiveNext - fLastAcknowledgeSent) >= (fReceiveMaxSegmentSize * 2)) {
// Trigger an immediate timeout rather than invoking Send directly,
// allowing multiple invocations to be coalesced.
delay = 0;
} else if (gStackModule->is_timer_active(&fDelayedAcknowledgeTimer)) {
return B_OK;
} }
gStackModule->set_timer(&fDelayedAcknowledgeTimer, gStackModule->set_timer(&fDelayedAcknowledgeTimer, delay);
TCP_DELAYED_ACKNOWLEDGE_TIMEOUT);
T(TimerSet(this, "delayed ack", TCP_DELAYED_ACKNOWLEDGE_TIMEOUT)); T(TimerSet(this, "delayed ack", TCP_DELAYED_ACKNOWLEDGE_TIMEOUT));
return B_OK; return B_OK;
} }