246 D. Wang et al.
variants [11,17,18], Viewstamped Replication [19] and Zab [15], reach an agree-
ment on each operation and ensure all replicas execute the operation in the same
order. Consensus is the fundamental problem in distributed systems and these
protocols have became the key component of large-scale and fault-tolerant data
store [6,10,21].
In contrast to the famous Paxos protocol, the recently proposed Raft algo-
rithm has better understandability and widely implemented in large amount of
open source projects [2,20]. During the execution of these consensus protocols
including the recently proposed Raft, log replication is a common and frequently
used operation which has significant impact on the system performance. In Raft,
a transaction can be committed if its log has been replicated on the majority of
followers. However, log replication algorithm also comes with inevitable perfor-
mance problems because of the latency caused by network and processing time
in followers (mainly from disk latency).
Raft achieves consensus among a group of members via an elected leader.
Only leader can accept new request from clients, and then replicates log entries
to followers. When the leader accept the acknowledgment from the majority of
followers, it commits the transaction and both leader and followers can safely
apply log entries to their replicas. In the naive implementation of Raft, the leader
propagates one request at a time. In general, this is highly ineffective because
multiple network transmissions increase the delay of each request. There are two
optimizations widely used in the implementation of consensus protocols [5,7,
12,13]: batching and pipeline. Batching is to pack several requests into a single
AppendEntries RPC, which spread the overhead on a set of requests. Pipeline
allows the leader to propagate a new AppendEntries RPC to followers before
the previous ones are acknowledged [16]. Pipeline can effectively improve the
throughput especially in the WAN network with high latency.
Although batching and pipeline can improve the performance of Raft con-
sensus protocol, the follower still needs to wait for flushing a batch to disk before
processing the next batch in the task queue which holds the many batches sent
by the leader. On the other hand, the strategy of replaying logs after they are
committed incurs a large amount of expensive memory copy operation (see the
details in the problem analysis section). To address these challenges, we redesign
the log replication scheme for Raft protocol. The basic idea is to separate flushing
a batch log from the log processing flow. Instead of directly writing the received
batch logs to disk by followers, the batch is immediately moved from the task
queue to a batch buffer. By this way, the next batch can be handled without
any blocking. A single thread is used to monitor the batch buffer, and asyn-
chronously flush a group of batch to disk in order to reduce disk IO overhead.
Furthermore, in order to decrease the operations of memory copy, the received
logs are also replayed immediately but the applied results are invisible until the
corresponding transaction are committed.
The time consuming on processing the logs by follower has significant impact
on the throughput and the end-to-end transaction response time as perceived by
the user. In this paper, we optimize the log flushing and replay in the follower,
评论