Skip to content

Commit 3b61568

Browse files
authored
server: Yield fiber if running for over 1ms (#5924)
When using epoll as the event loop in debug mode, it has been observed that the stream consumption from redis in stable state can monopolize the core allowing no other fibers to run. To avoid this a yield is added similar to ListenerInterface::RunAcceptLoop() Signed-off-by: Abhijat Malviya <[email protected]>
1 parent 2a8806a commit 3b61568

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/server/replica.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,11 +693,16 @@ error_code Replica::ConsumeRedisStream() {
693693
};
694694
RETURN_ON_ERR(exec_st_.SwitchErrorHandler(std::move(err_handler)));
695695

696-
facade::CmdArgVec args_vector;
696+
CmdArgVec args_vector;
697697

698698
acks_fb_ = fb2::Fiber("redis_acks", &Replica::RedisStreamAcksFb, this);
699699

700700
while (true) {
701+
// Yield if the fiber has been running for long.
702+
if (base::CycleClock::ToUsec(ThisFiber::GetRunningTimeCycles()) > 1000) { // 1ms
703+
ThisFiber::Yield();
704+
}
705+
701706
auto response = ReadRespReply(&io_buf, /*copy_msg=*/false);
702707
if (!response.has_value()) {
703708
LOG_REPL_ERROR("Error in Redis Stream at phase "

0 commit comments

Comments
 (0)