From 1c942386b66f262fed371c7bee7ab42b54e23632 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Wed, 14 Jan 2015 15:49:58 -0800 Subject: [PATCH] consul: Use new LogCache to improve write throughput --- consul/server.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/consul/server.go b/consul/server.go index 6a267025e7..14b9bd5ad1 100644 --- a/consul/server.go +++ b/consul/server.go @@ -49,6 +49,10 @@ const ( // Maximum number of cached ACL entries aclCacheSize = 256 + + // raftLogCacheSize is the maximum number of logs to cache in-memory. + // This is used to reduce disk I/O for the recently commited entries. + raftLogCacheSize = 512 ) // Server is Consul server which manages the service discovery, @@ -362,6 +366,13 @@ func (s *Server) setupRaft() error { } s.raftStore = store + // Wrap the store in a LogCache to improve performance + cacheStore, err := raft.NewLogCache(raftLogCacheSize, store) + if err != nil { + store.Close() + return err + } + // Create the snapshot store snapshots, err := raft.NewFileSnapshotStore(path, snapshotsRetained, s.config.LogOutput) if err != nil { @@ -392,7 +403,7 @@ func (s *Server) setupRaft() error { s.config.RaftConfig.LogOutput = s.config.LogOutput // Setup the Raft store - s.raft, err = raft.NewRaft(s.config.RaftConfig, s.fsm, store, store, + s.raft, err = raft.NewRaft(s.config.RaftConfig, s.fsm, cacheStore, store, snapshots, s.raftPeers, trans) if err != nil { store.Close()