mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-12 14:27:27 -08:00
[ENHANCEMENT] TSDB: Reduce map lookups on exemplar index
In many cases we already have a pointer to the entry. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
f0c50b5a66
commit
3eb5581877
|
@ -371,11 +371,12 @@ func (ce *CircularExemplarStorage) AddExemplar(l labels.Labels, e exemplar.Exemp
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, ok := ce.index[string(seriesLabels)]
|
idx, ok := ce.index[string(seriesLabels)]
|
||||||
if !ok {
|
if !ok {
|
||||||
ce.index[string(seriesLabels)] = &indexEntry{oldest: ce.nextIndex, seriesLabels: l}
|
idx = &indexEntry{oldest: ce.nextIndex, seriesLabels: l}
|
||||||
|
ce.index[string(seriesLabels)] = idx
|
||||||
} else {
|
} else {
|
||||||
ce.exemplars[ce.index[string(seriesLabels)].newest].next = ce.nextIndex
|
ce.exemplars[idx.newest].next = ce.nextIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
if prev := ce.exemplars[ce.nextIndex]; prev == nil {
|
if prev := ce.exemplars[ce.nextIndex]; prev == nil {
|
||||||
|
@ -383,13 +384,13 @@ func (ce *CircularExemplarStorage) AddExemplar(l labels.Labels, e exemplar.Exemp
|
||||||
} else {
|
} else {
|
||||||
// There exists an exemplar already on this ce.nextIndex entry,
|
// There exists an exemplar already on this ce.nextIndex entry,
|
||||||
// drop it, to make place for others.
|
// drop it, to make place for others.
|
||||||
var buf [1024]byte
|
|
||||||
prevLabels := prev.ref.seriesLabels.Bytes(buf[:])
|
|
||||||
if prev.next == noExemplar {
|
if prev.next == noExemplar {
|
||||||
// Last item for this series, remove index entry.
|
// Last item for this series, remove index entry.
|
||||||
|
var buf [1024]byte
|
||||||
|
prevLabels := prev.ref.seriesLabels.Bytes(buf[:])
|
||||||
delete(ce.index, string(prevLabels))
|
delete(ce.index, string(prevLabels))
|
||||||
} else {
|
} else {
|
||||||
ce.index[string(prevLabels)].oldest = prev.next
|
prev.ref.oldest = prev.next
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,8 +398,8 @@ func (ce *CircularExemplarStorage) AddExemplar(l labels.Labels, e exemplar.Exemp
|
||||||
// since this is the first exemplar stored for this series.
|
// since this is the first exemplar stored for this series.
|
||||||
ce.exemplars[ce.nextIndex].next = noExemplar
|
ce.exemplars[ce.nextIndex].next = noExemplar
|
||||||
ce.exemplars[ce.nextIndex].exemplar = e
|
ce.exemplars[ce.nextIndex].exemplar = e
|
||||||
ce.exemplars[ce.nextIndex].ref = ce.index[string(seriesLabels)]
|
ce.exemplars[ce.nextIndex].ref = idx
|
||||||
ce.index[string(seriesLabels)].newest = ce.nextIndex
|
idx.newest = ce.nextIndex
|
||||||
|
|
||||||
ce.nextIndex = (ce.nextIndex + 1) % len(ce.exemplars)
|
ce.nextIndex = (ce.nextIndex + 1) % len(ce.exemplars)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue