| In a distributed system environment,it is often necessary to rely on distributed consensus algorithm solutions for more secure data storage and to provide highly available services.Raft is a fast,scalable,and easy-to-understand consensus algorithm widely used in distributed systems.The algorithm relies on a single leader to process client requests and communicate with other servers to reach consensus,so a stable,reliable,and robust node as a leader is critical to the cluster.Since a random timeout election mechanism is used to elect the leader in the Raft algorithm,multiple candidates may divide the votes at the same time.Random election is unfair for nodes with different performance characteristics,and we want to elect nodes with good hardware configuration as leaders to provide services,which cannot be satisfied in the Raft algorithm.At the same time,in the Raft cluster operation,the leaders will appear to run slowly,and we would like to be able to replace the current leaders through leader reelection to ensure the high throughput and low latency requirements unique to distributed applications.During the log replication phase,the leader nodes handle most of the requests and are easily called system performance bottlenecks,yet the followers have a lot of idle resources that cannot be fully utilized.If the follower nodes can also participate in log replication,then it will improve the read and write throughput of the system.To address the above issues,the Raft algorithm is optimized and improved in this paper from two phases,leader election and log replication.The main studies are as follows.(1)The Raft consensus algorithm is optimized from two stages: leader election and leader change.In the leader election phase,this paper designs a priority-based voting mechanism to make the elected leaders as reliable as possible and provide highperformance reads and writes.In the leader change phase,this paper designs a mechanism to actively trigger a new round of election so that Leader nodes can be actively transformed into followers under certain conditions to enhance the symmetry among servers.In addition to active withdrawal,an opposition mechanism is also set to trigger a new round of leader election,so that the leader nodes in the Raft cluster always maintain high performance read and write.The optimized Raft algorithm is experimentally able to improve the throughput by 20% compared to the original Raft algorithm during periods of poor leader performance.(2)A collaboration-based log replication algorithm is proposed.This algorithm is used to solve the performance bottleneck problem of a single leader,where the leader selects followers based on priority to collaborate together for log replication.The leader node and the follower node replicate a batch of logs simultaneously,and each node is responsible for replicating a segment of logs in the batch.This algorithm utilizes the idle resources of the follower nodes to improve the throughput of the Raft algorithm and optimize the consensus efficiency. |