vmselect:fix init sn take too much time (#4366)

* vmselect: descrease start time for vmselect

https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4364
This commit is contained in:
Haleygo 2023-05-30 19:04:31 +08:00 committed by GitHub
parent c30f0e51d7
commit 6c84b61893
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2697,9 +2697,14 @@ func initStorageNodes(addrs []string) *storageNodesBucket {
if len(addrs) == 0 { if len(addrs) == 0 {
logger.Panicf("BUG: addrs must be non-empty") logger.Panicf("BUG: addrs must be non-empty")
} }
var snsLock sync.Mutex
sns := make([]*storageNode, 0, len(addrs)) sns := make([]*storageNode, 0, len(addrs))
var wg sync.WaitGroup
ms := metrics.NewSet() ms := metrics.NewSet()
for _, addr := range addrs { for _, addr := range addrs {
wg.Add(1)
go func(addr string) {
defer wg.Done()
if _, _, err := net.SplitHostPort(addr); err != nil { if _, _, err := net.SplitHostPort(addr); err != nil {
// Automatically add missing port. // Automatically add missing port.
addr += ":8401" addr += ":8401"
@ -2734,8 +2739,12 @@ func initStorageNodes(addrs []string) *storageNodesBucket {
metricBlocksRead: ms.NewCounter(fmt.Sprintf(`vm_metric_blocks_read_total{name="vmselect", addr=%q}`, addr)), metricBlocksRead: ms.NewCounter(fmt.Sprintf(`vm_metric_blocks_read_total{name="vmselect", addr=%q}`, addr)),
metricRowsRead: ms.NewCounter(fmt.Sprintf(`vm_metric_rows_read_total{name="vmselect", addr=%q}`, addr)), metricRowsRead: ms.NewCounter(fmt.Sprintf(`vm_metric_rows_read_total{name="vmselect", addr=%q}`, addr)),
} }
snsLock.Lock()
sns = append(sns, sn) sns = append(sns, sn)
snsLock.Unlock()
}(addr)
} }
wg.Wait()
metrics.RegisterSet(ms) metrics.RegisterSet(ms)
return &storageNodesBucket{ return &storageNodesBucket{
sns: sns, sns: sns,