Explorar el Código

add peerUpdate call 1 min limit

Max Ma hace 10 meses
padre
commit
b79d03199c
Se han modificado 1 ficheros con 8 adiciones y 1 borrados
  1. 8 1
      mq/publishers.go

+ 8 - 1
mq/publishers.go

@@ -18,10 +18,17 @@ import (
 
 var batchSize = servercfg.GetPeerUpdateBatchSize()
 var batchUpdate = servercfg.GetBatchPeerUpdate()
+var peerUpdateTS = time.Now().Unix()
 
 // PublishPeerUpdate --- determines and publishes a peer update to all the hosts
 func PublishPeerUpdate(replacePeers bool) error {
 	slog.Error("entering PublishPeerUpdate", "Debug")
+	t1 := time.Now().Unix()
+	if time.Now().Unix()-peerUpdateTS < 60 {
+		return nil
+	}
+	peerUpdateTS = time.Now().Unix()
+
 	pc, file, no, ok := runtime.Caller(1)
 	if ok {
 		slog.Error("called from ", file, no)
@@ -85,7 +92,7 @@ func PublishPeerUpdate(replacePeers bool) error {
 		}
 		wg.Wait()
 	}
-	slog.Error("leaving PublishPeerUpdate", "Debug")
+	slog.Error("leaving PublishPeerUpdate, time cost: ", "Debug", time.Now().Unix()-t1)
 	return nil
 }