Explorar o código

add peerUpdate batch size to config

Max Ma hai 1 ano
pai
achega
e6921ff233
Modificáronse 2 ficheiros con 17 adicións e 2 borrados
  1. 4 2
      mq/publishers.go
  2. 13 0
      servercfg/serverconf.go

+ 4 - 2
mq/publishers.go

@@ -14,7 +14,7 @@ import (
 	"golang.org/x/exp/slog"
 )
 
-const batchSize = 20
+var batch int
 
 // PublishPeerUpdate --- determines and publishes a peer update to all the hosts
 func PublishPeerUpdate(replacePeers bool) error {
@@ -34,7 +34,9 @@ func PublishPeerUpdate(replacePeers bool) error {
 
 	var wg sync.WaitGroup
 	hostLen := len(hosts)
-	batch := batchSize
+	if batch == 0 {
+		batch = servercfg.GetPeerUpdateBatchSize()
+	}
 	div := hostLen / batch
 	mod := hostLen % batch
 

+ 13 - 0
servercfg/serverconf.go

@@ -597,6 +597,19 @@ func GetMetricInterval() string {
 	return mi
 }
 
+// GetPeerUpdateBatchSize - get the batch size for peer update
+func GetPeerUpdateBatchSize() int {
+	//default 50
+	batchSize := 50
+	if os.Getenv("PEER_UPDATE_BATCH_SIZE") != "" {
+		b, e := strconv.Atoi(os.Getenv("PEER_UPDATE_BATCH_SIZE"))
+		if e == nil && b > 0 && b < 1000 {
+			batchSize = b
+		}
+	}
+	return batchSize
+}
+
 // GetEmqxRestEndpoint - returns the REST API Endpoint of EMQX
 func GetEmqxRestEndpoint() string {
 	return os.Getenv("EMQX_REST_ENDPOINT")