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:
Brian Brazil 2018-10-31 12:51:21 +00:00
parent f0e79ec264
commit d8c8e4e6e4
1 changed files with 10 additions and 3 deletions

13
head.go
View File

@ -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 {