func (h *hive) startRaftNode() { peers := make([]etcdraft.Peer, 0, 1) if len(h.meta.Peers) != 0 { h.registry.initHives(h.meta.Peers) } else { i := h.info() ni := raft.GroupNode{ Group: hiveGroup, Node: i.ID, Data: i.Addr, } peers = append(peers, ni.Peer()) } h.ticker = randtime.NewTicker(h.config.RaftTick, h.config.RaftTickDelta) ncfg := raft.Config{ ID: h.id, Name: h.String(), Send: h.sendRaft, Ticker: h.ticker.C, } h.node = raft.StartMultiNode(ncfg) gcfg := raft.GroupConfig{ ID: hiveGroup, Name: h.String(), StateMachine: h.registry, Peers: peers, DataDir: h.config.StatePath, SnapCount: 1024, FsyncTick: h.config.RaftFsyncTick, ElectionTicks: h.config.RaftElectTicks, HeartbeatTicks: h.config.RaftHBTicks, MaxInFlights: h.config.RaftInFlights, MaxMsgSize: h.config.RaftMaxMsgSize, } if err := h.node.CreateGroup(context.TODO(), gcfg); err != nil { glog.Fatalf("cannot create hive group: %v", err) } }
func BenchmarkBeePersistence(b *testing.B) { b.StopTimer() log.SetOutput(ioutil.Discard) hive := &hive{ id: 1, config: HiveConfig{ StatePath: "/tmp/bhtest_bench_bee", RaftTick: 100 * time.Millisecond, RaftHBTicks: 1, RaftElectTicks: 5, RaftInFlights: 1, RaftFsyncTick: 1 * time.Second, }, collector: &noOpStatCollector{}, } removeState(hive.config.StatePath) hive.ticker = randtime.NewTicker(hive.config.RaftTick, 0) hive.registry = newRegistry(hive.String()) ncfg := raft.Config{ ID: hive.id, Name: hive.String(), Send: hive.sendRaft, Ticker: hive.ticker.C, } hive.node = raft.StartMultiNode(ncfg) bee := bee{ beeID: 1, beeColony: Colony{ ID: 1, Leader: 1, }, hive: hive, app: &app{ name: "test", flags: appFlagTransactional | appFlagPersistent, }, stateL1: state.NewTransactional(state.NewInMem()), dataCh: newMsgChannel(uint(b.N)), batchSize: 1024, } bee.becomeLeader() hive.registry.addBee(BeeInfo{ ID: 1, Hive: 1, App: "test", Colony: bee.colony(), }) if err := bee.createGroup(); err != nil { b.Fatal(err) } b.StartTimer() h := benchBeeHandler{data: []byte{1, 1, 1, 1}} mhs := make([]msgAndHandler, bee.batchSize) for j := uint(0); j < bee.batchSize; j++ { mhs[j] = msgAndHandler{ msg: &msg{}, handler: h, } } for i := uint(0); i < uint(b.N); i += bee.batchSize { bee.handleMsg(mhs) } b.StopTimer() time.Sleep(1 * time.Second) hive.node.Stop() }