mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
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
9
head.go
9
head.go
|
@ -242,6 +242,9 @@ func (h *Head) processWALSamples(
|
||||||
) (unknownRefs uint64) {
|
) (unknownRefs uint64) {
|
||||||
defer close(output)
|
defer close(output)
|
||||||
|
|
||||||
|
// Mitigate lock contention in getByID.
|
||||||
|
refSeries := map[uint64]*memSeries{}
|
||||||
|
|
||||||
mint, maxt := int64(math.MaxInt64), int64(math.MinInt64)
|
mint, maxt := int64(math.MaxInt64), int64(math.MinInt64)
|
||||||
|
|
||||||
for samples := range input {
|
for samples := range input {
|
||||||
|
@ -249,11 +252,15 @@ func (h *Head) processWALSamples(
|
||||||
if s.T < minValidTime || s.Ref%total != partition {
|
if s.T < minValidTime || s.Ref%total != partition {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ms := h.series.getByID(s.Ref)
|
ms := refSeries[s.Ref]
|
||||||
|
if ms == nil {
|
||||||
|
ms = h.series.getByID(s.Ref)
|
||||||
if ms == nil {
|
if ms == nil {
|
||||||
unknownRefs++
|
unknownRefs++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
refSeries[s.Ref] = ms
|
||||||
|
}
|
||||||
_, chunkCreated := ms.append(s.T, s.V)
|
_, chunkCreated := ms.append(s.T, s.V)
|
||||||
if chunkCreated {
|
if chunkCreated {
|
||||||
h.metrics.chunksCreated.Inc()
|
h.metrics.chunksCreated.Inc()
|
||||||
|
|
Loading…
Reference in a new issue