Keep local cache of ids.
With the various goroutines running, the locking in getByID is notable. This cuts cpu usage by ~25% and walltime by ~20%. Signed-off-by: Brian Brazil <brian.brazil@robustperception.io>
This commit is contained in:
parent
f0e79ec264
commit
d8c8e4e6e4
13
head.go
13
head.go
|
@ -242,6 +242,9 @@ func (h *Head) processWALSamples(
|
|||
) (unknownRefs uint64) {
|
||||
defer close(output)
|
||||
|
||||
// Mitigate lock contention in getByID.
|
||||
refSeries := map[uint64]*memSeries{}
|
||||
|
||||
mint, maxt := int64(math.MaxInt64), int64(math.MinInt64)
|
||||
|
||||
for samples := range input {
|
||||
|
@ -249,10 +252,14 @@ func (h *Head) processWALSamples(
|
|||
if s.T < minValidTime || s.Ref%total != partition {
|
||||
continue
|
||||
}
|
||||
ms := h.series.getByID(s.Ref)
|
||||
ms := refSeries[s.Ref]
|
||||
if ms == nil {
|
||||
unknownRefs++
|
||||
continue
|
||||
ms = h.series.getByID(s.Ref)
|
||||
if ms == nil {
|
||||
unknownRefs++
|
||||
continue
|
||||
}
|
||||
refSeries[s.Ref] = ms
|
||||
}
|
||||
_, chunkCreated := ms.append(s.T, s.V)
|
||||
if chunkCreated {
|
||||
|
|
Loading…
Reference in New Issue