mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-01-10 15:14:09 +00:00
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:
parent
c30f0e51d7
commit
6c84b61893
1 changed files with 41 additions and 32 deletions
|
@ -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,
|
||||||
|
|
Loading…
Reference in a new issue