Skip to content

Commit

Permalink
USe goroutines to avoid blocking timers
Browse files Browse the repository at this point in the history
  • Loading branch information
gdiazlo committed Dec 5, 2018
1 parent 0bd32f1 commit 9eb4a60
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
9 changes: 3 additions & 6 deletions gossip/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ func NewAgent(conf *Config, p []Processor) (agent *Agent, err error) {
}

func (a *Agent) start() {

outTicker := time.NewTicker(2 * time.Second)
alertTicker := time.NewTicker(1 * time.Second)

Expand All @@ -150,15 +149,13 @@ func (a *Agent) start() {
}
a.Out <- batch
case <-outTicker.C:
a.sendOutQueue()
go a.sendOutQueue()
case <-alertTicker.C:
a.processAlertQueue()
go a.processAlertQueue()
case <-a.quit:
return
}

}

}

func (a *Agent) processAlertQueue() {
Expand Down Expand Up @@ -204,7 +201,7 @@ func (a *Agent) sendOutQueue() {
batch.From = a.Self
msg, _ := batch.Encode()
for _, dst := range a.route(from) {
fmt.Printf("agent.sendOutQueue(): sending %+v to %+v\n", batchId(batch), dst.Name)
log.Debugf("Sending %+v to %+v\n", batchId(batch), dst.Name)
a.memberlist.SendReliable(dst, msg)
}
}
Expand Down
12 changes: 7 additions & 5 deletions gossip/sender/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ func (s Sender) Start(ch chan *protocol.Snapshot) {

for _, peer := range peers.L {
dst := peer.Node()
fmt.Printf("sender(): Sending batch %+v to node %+v\n", batch, dst.Name)
err := s.Agent.Memberlist().SendReliable(dst, msg)
if err != nil {
log.Errorf("Failed send message: %v", err)
}
log.Infof("Sending batch %+v to node %+v\n", batch, dst.Name)
go func() {
err := s.Agent.Memberlist().SendReliable(dst, msg)
if err != nil {
log.Errorf("Failed send message: %v", err)
}
}()
}
case <-s.quit:
return
Expand Down

0 comments on commit 9eb4a60

Please sign in to comment.