1
0
mirror of https://github.com/facebookincubator/mvfst.git synced 2025-11-09 10:00:57 +03:00

Add option to do an inline write after a read event.

Summary: Presently updateWriteLooper will always schedule a loop callback to do the write loop. Add an option to inline trigger the writes after the read event.

Reviewed By: kvtsoy, sharmafb

Differential Revision: D62192192

fbshipit-source-id: 30991608f57fbfa097a7522c0731d25b8e528345
This commit is contained in:
Matt Joras
2024-09-04 15:15:22 -07:00
committed by Facebook GitHub Bot
parent a87f7bdbcb
commit e81c40b2f7
5 changed files with 16 additions and 6 deletions

View File

@@ -1114,7 +1114,7 @@ void QuicTransportBase::updatePeekLooper() {
} }
} }
void QuicTransportBase::updateWriteLooper(bool thisIteration) { void QuicTransportBase::updateWriteLooper(bool thisIteration, bool runInline) {
if (closeState_ == CloseState::CLOSED) { if (closeState_ == CloseState::CLOSED) {
VLOG(10) << nodeToString(conn_->nodeType) VLOG(10) << nodeToString(conn_->nodeType)
<< " stopping write looper because conn closed " << *this; << " stopping write looper because conn closed " << *this;
@@ -1141,7 +1141,7 @@ void QuicTransportBase::updateWriteLooper(bool thisIteration) {
VLOG(10) << nodeToString(conn_->nodeType) VLOG(10) << nodeToString(conn_->nodeType)
<< " running write looper thisIteration=" << thisIteration << " " << " running write looper thisIteration=" << thisIteration << " "
<< *this; << *this;
writeLooper_->run(thisIteration); writeLooper_->run(thisIteration, runInline);
if (conn_->loopDetectorCallback) { if (conn_->loopDetectorCallback) {
conn_->writeDebugState.needsWriteLoopDetect = conn_->writeDebugState.needsWriteLoopDetect =
(conn_->loopDetectorCallback != nullptr); (conn_->loopDetectorCallback != nullptr);
@@ -1878,7 +1878,7 @@ void QuicTransportBase::onNetworkData(
checkForClosedStream(); checkForClosedStream();
updateReadLooper(); updateReadLooper();
updatePeekLooper(); updatePeekLooper();
updateWriteLooper(true); updateWriteLooper(true, conn_->transportSettings.inlineWriteAfterRead);
}; };
try { try {
conn_->lossState.totalBytesRecvd += networkData.getTotalData(); conn_->lossState.totalBytesRecvd += networkData.getTotalData();

View File

@@ -705,7 +705,7 @@ class QuicTransportBase : public QuicSocket,
void invokeStreamsAvailableCallbacks(); void invokeStreamsAvailableCallbacks();
void updateReadLooper(); void updateReadLooper();
void updatePeekLooper(); void updatePeekLooper();
void updateWriteLooper(bool thisIteration); void updateWriteLooper(bool thisIteration, bool runInline = false);
void handlePingCallbacks(); void handlePingCallbacks();
void handleKnobCallbacks(); void handleKnobCallbacks();
void handleAckEventCallbacks(); void handleAckEventCallbacks();

View File

@@ -75,7 +75,7 @@ void FunctionLooper::runLoopCallback() noexcept {
commonLoopBody(); commonLoopBody();
} }
void FunctionLooper::run(bool thisIteration) noexcept { void FunctionLooper::run(bool thisIteration, bool runInline) noexcept {
VLOG(10) << __func__ << ": " << type_; VLOG(10) << __func__ << ": " << type_;
running_ = true; running_ = true;
// Caller can call run() in func_. But if we are in pacing mode, we should // Caller can call run() in func_. But if we are in pacing mode, we should
@@ -85,6 +85,13 @@ void FunctionLooper::run(bool thisIteration) noexcept {
<< " in loop body and using pacing - not rescheduling"; << " in loop body and using pacing - not rescheduling";
return; return;
} }
if (runInline) {
// Running inline, manually trigger a loop body and cancel the loop
// callback if it was scheduled.
cancelLoopCallback();
commonLoopBody();
return;
}
if (isLoopCallbackScheduled() || if (isLoopCallbackScheduled() ||
(!fireLoopEarly_ && pacingTimer_ && isTimerCallbackScheduled())) { (!fireLoopEarly_ && pacingTimer_ && isTimerCallbackScheduled())) {
VLOG(10) << __func__ << ": " << type_ << " already scheduled"; VLOG(10) << __func__ << ": " << type_ << " already scheduled";

View File

@@ -51,7 +51,7 @@ class FunctionLooper : public QuicEventBaseLoopCallback,
* Starts running the loop callback in each loop iteration. * Starts running the loop callback in each loop iteration.
* if this is already scheduled to run, run() will continue to run it. * if this is already scheduled to run, run() will continue to run it.
*/ */
void run(bool thisIteration = false) noexcept; void run(bool thisIteration = false, bool runInline = false) noexcept;
void setPacingFunction( void setPacingFunction(
folly::Function<std::chrono::microseconds()>&& pacingFunc); folly::Function<std::chrono::microseconds()>&& pacingFunc);

View File

@@ -403,6 +403,9 @@ struct TransportSettings {
bool checkIdleTimerOnWrite{false}; bool checkIdleTimerOnWrite{false};
// Whether to process callbacks per received packet. // Whether to process callbacks per received packet.
bool processCallbacksPerPacket{false}; bool processCallbacksPerPacket{false};
// Whether to trigger an inline write loop after we've read packets, rather
// than deferring to a loop callback.
bool inlineWriteAfterRead{false};
}; };
} // namespace quic } // namespace quic