From 288d13af8dc9c42f5addcccc1850ca6aa4dcd404 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 21 Jun 2022 13:30:58 +0300 Subject: [PATCH] lib/netutil: parallelize background pings for remote addresses This should improve the time needed for determining unavailale remote addresses across big numer of ConnPool's. This is a follow-up for a1629bd3be500c218a202f86c1360849baece483 Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/711 --- lib/netutil/conn_pool.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/netutil/conn_pool.go b/lib/netutil/conn_pool.go index 4e5d70889..43411471d 100644 --- a/lib/netutil/conn_pool.go +++ b/lib/netutil/conn_pool.go @@ -222,8 +222,14 @@ var connPools []*ConnPool func forEachConnPool(f func(cp *ConnPool)) { connPoolsMu.Lock() + var wg sync.WaitGroup for _, cp := range connPools { - f(cp) + wg.Add(1) + go func(cp *ConnPool) { + defer wg.Done() + f(cp) + }(cp) } + wg.Wait() connPoolsMu.Unlock() }