Skip to content

Commit

Permalink
chore: partially revert adjust batching behavior to reduce network (#…
Browse files Browse the repository at this point in the history
…1821)

* partially reverts #1777
  • Loading branch information
kostasrim committed Sep 8, 2023
1 parent fb5ae98 commit 55737a6
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions src/facade/dragonfly_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -799,28 +799,12 @@ void Connection::DispatchFiber(util::FiberSocketBase* peer) {

size_t squashing_threshold = absl::GetFlag(FLAGS_pipeline_squash);

uint64_t prev_epoch = fb2::FiberSwitchEpoch();
while (!builder->GetError()) {
evc_.await(
[this] { return cc_->conn_closing || (!dispatch_q_.empty() && !cc_->sync_dispatch); });
if (cc_->conn_closing)
break;

// We really want to have batching in the builder if possible. This is especially
// critical in situations where Nagle's algorithm can introduce unwanted high
// latencies. However we can only batch if we're sure that there are more commands
// on the way that will trigger a flush. To know if there are, we sometimes yield before
// executing the last command in the queue and let the producer fiber push more commands if it
// wants to.
// As an optimization, we only yield if the fiber was not suspended since the last dispatch.
uint64_t cur_epoch = fb2::FiberSwitchEpoch();
if (dispatch_q_.size() == 1 && cur_epoch == prev_epoch) {
ThisFiber::Yield();
DVLOG(1) << "After yielding to producer, dispatch_q_.size()=" << dispatch_q_.size();
}
prev_epoch = cur_epoch;
builder->SetBatchMode(dispatch_q_.size() > 1);

auto recycle = [this, request_cache_limit](MessageHandle msg) {
dispatch_q_bytes_.fetch_sub(msg.UsedMemory(), memory_order_relaxed);

Expand All @@ -834,6 +818,8 @@ void Connection::DispatchFiber(util::FiberSocketBase* peer) {
}
};

builder->SetBatchMode(dispatch_q_.size() > 1);

// Special case: if the dispatch queue accumulated a big number of commands,
// we can try to squash them
// It is only enabled if the threshold is reached and the whole dispatch queue
Expand Down

0 comments on commit 55737a6

Please sign in to comment.