Skip to content

Commit

Permalink
Merge c5510d6 into 4d932ba
Browse files Browse the repository at this point in the history
  • Loading branch information
derekcollison committed Feb 12, 2019
2 parents 4d932ba + c5510d6 commit f0405ad
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 29 deletions.
2 changes: 1 addition & 1 deletion server/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var (

const (
// VERSION is the current version for the server.
VERSION = "2.0.0-RC3"
VERSION = "2.0.0-RC4"

// PROTO is the currently supported protocol.
// 0 was the original
Expand Down
27 changes: 1 addition & 26 deletions server/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package server
import (
"encoding/json"
"fmt"
"math/rand"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -445,7 +444,7 @@ func (s *Server) initEventTracking() {
s.Errorf("Error setting up internal tracking: %v", err)
}
// Listen for ping messages that will be sent to all servers for statsz.
if _, err := s.sysSubscribe(serverStatsPingReqSubj, s.statszPing); err != nil {
if _, err := s.sysSubscribe(serverStatsPingReqSubj, s.statszReq); err != nil {
s.Errorf("Error setting up internal tracking: %v", err)
}
}
Expand Down Expand Up @@ -572,30 +571,6 @@ func (s *Server) connsRequest(sub *subscription, subject, reply string, msg []by
}
}

// random back off interval for broadcast statsz ping requests.
const randomBackoff = 250 * time.Millisecond

// statszPing will handle global requests for our server statsz. This will be a
// broadcast msg so we want to be mindful of that. We will do a random backoff and
// process in a separate go routine.
func (s *Server) statszPing(sub *subscription, subject, reply string, msg []byte) {
if !s.EventsEnabled() || reply == _EMPTY_ {
return
}
s.startGoRoutine(func() {
defer s.grWG.Done()
delay := time.Duration(rand.Intn(int(randomBackoff)))
select {
case <-time.After(delay):
s.mu.Lock()
defer s.mu.Unlock()
s.sendStatsz(reply)
case <-s.quitCh:
return
}
})
}

// statszReq is a request for us to respond with current statz.
func (s *Server) statszReq(sub *subscription, subject, reply string, msg []byte) {
s.mu.Lock()
Expand Down
4 changes: 2 additions & 2 deletions server/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1178,14 +1178,14 @@ func TestServerEventsPingStatsZ(t *testing.T) {
m := ServerStatsMsg{}

// Receive both manually.
msg, err := sub.NextMsg(randomBackoff * 2)
msg, err := sub.NextMsg(time.Second)
if err != nil {
t.Fatalf("Error receiving msg: %v", err)
}
if err := json.Unmarshal(msg.Data, &m); err != nil {
t.Fatalf("Error unmarshalling the statz json: %v", err)
}
msg, err = sub.NextMsg(randomBackoff)
msg, err = sub.NextMsg(time.Second)
if err != nil {
t.Fatalf("Error receiving msg: %v", err)
}
Expand Down

0 comments on commit f0405ad

Please sign in to comment.