mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
app/vmselect/netstorage: re-use random generator used for series shuffle in Result.RunParallel
This should reduce CPU usage needed for rand.Rand initialization
This commit is contained in:
parent
90649de0c4
commit
19a0b4679a
1 changed files with 16 additions and 1 deletions
|
@ -182,10 +182,11 @@ func (rss *Results) RunParallel(qt *querytracer.Tracer, f func(rs *Result, worke
|
||||||
tsws[i] = tsw
|
tsws[i] = tsw
|
||||||
}
|
}
|
||||||
// Shuffle tsws for providing the equal amount of work among workers.
|
// Shuffle tsws for providing the equal amount of work among workers.
|
||||||
r := rand.New(rand.NewSource(int64(fasttime.UnixTimestamp())))
|
r := getRand()
|
||||||
r.Shuffle(len(tsws), func(i, j int) {
|
r.Shuffle(len(tsws), func(i, j int) {
|
||||||
tsws[i], tsws[j] = tsws[j], tsws[i]
|
tsws[i], tsws[j] = tsws[j], tsws[i]
|
||||||
})
|
})
|
||||||
|
putRand(r)
|
||||||
|
|
||||||
// Spin up up to gomaxprocs local workers and split work equally among them.
|
// Spin up up to gomaxprocs local workers and split work equally among them.
|
||||||
// This guarantees linear scalability with the increase of gomaxprocs
|
// This guarantees linear scalability with the increase of gomaxprocs
|
||||||
|
@ -240,6 +241,20 @@ func (rss *Results) RunParallel(qt *querytracer.Tracer, f func(rs *Result, worke
|
||||||
return firstErr
|
return firstErr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var randPool sync.Pool
|
||||||
|
|
||||||
|
func getRand() *rand.Rand {
|
||||||
|
v := randPool.Get()
|
||||||
|
if v == nil {
|
||||||
|
v = rand.New(rand.NewSource(int64(fasttime.UnixTimestamp())))
|
||||||
|
}
|
||||||
|
return v.(*rand.Rand)
|
||||||
|
}
|
||||||
|
|
||||||
|
func putRand(r *rand.Rand) {
|
||||||
|
randPool.Put(r)
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
rowsReadPerSeries = metrics.NewHistogram(`vm_rows_read_per_series`)
|
rowsReadPerSeries = metrics.NewHistogram(`vm_rows_read_per_series`)
|
||||||
rowsReadPerQuery = metrics.NewHistogram(`vm_rows_read_per_query`)
|
rowsReadPerQuery = metrics.NewHistogram(`vm_rows_read_per_query`)
|
||||||
|
|
Loading…
Reference in a new issue