mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
tsdb: use cheaper Mutex on series
Mutex is 8 bytes; RWMutex is 24 bytes and much more complicated. Since `RLock` is only used in two places, `UpdateMetadata` and `Delete`, neither of which are hotspots, we should use the cheaper one. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
a598ddfbc4
commit
66237c1996
|
@ -1484,9 +1484,9 @@ func (h *Head) Delete(ctx context.Context, mint, maxt int64, ms ...*labels.Match
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
series.RLock()
|
series.Lock()
|
||||||
t0, t1 := series.minTime(), series.maxTime()
|
t0, t1 := series.minTime(), series.maxTime()
|
||||||
series.RUnlock()
|
series.Unlock()
|
||||||
if t0 == math.MinInt64 || t1 == math.MinInt64 {
|
if t0 == math.MinInt64 || t1 == math.MinInt64 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -2016,7 +2016,7 @@ func (s sample) Type() chunkenc.ValueType {
|
||||||
// memSeries is the in-memory representation of a series. None of its methods
|
// memSeries is the in-memory representation of a series. None of its methods
|
||||||
// are goroutine safe and it is the caller's responsibility to lock it.
|
// are goroutine safe and it is the caller's responsibility to lock it.
|
||||||
type memSeries struct {
|
type memSeries struct {
|
||||||
sync.RWMutex
|
sync.Mutex
|
||||||
|
|
||||||
ref chunks.HeadSeriesRef
|
ref chunks.HeadSeriesRef
|
||||||
lset labels.Labels
|
lset labels.Labels
|
||||||
|
|
|
@ -684,9 +684,9 @@ func (a *headAppender) UpdateMetadata(ref storage.SeriesRef, lset labels.Labels,
|
||||||
return 0, fmt.Errorf("unknown series when trying to add metadata with HeadSeriesRef: %d and labels: %s", ref, lset)
|
return 0, fmt.Errorf("unknown series when trying to add metadata with HeadSeriesRef: %d and labels: %s", ref, lset)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.RLock()
|
s.Lock()
|
||||||
hasNewMetadata := s.meta == nil || *s.meta != meta
|
hasNewMetadata := s.meta == nil || *s.meta != meta
|
||||||
s.RUnlock()
|
s.Unlock()
|
||||||
|
|
||||||
if hasNewMetadata {
|
if hasNewMetadata {
|
||||||
a.metadata = append(a.metadata, record.RefMetadata{
|
a.metadata = append(a.metadata, record.RefMetadata{
|
||||||
|
|
Loading…
Reference in a new issue