mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-27 06:29:42 -08:00
Avoid redundant fingerprint calculation.
Change-Id: Ief8a165dcfa5030226953346ec9dfe4a7787df1f
This commit is contained in:
parent
e9ff29c547
commit
aea32b0b4b
|
@ -131,7 +131,7 @@ func newMemorySeries(m clientmodel.Metric) *memorySeries {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *memorySeries) add(v *metric.SamplePair, persistQueue chan *persistRequest) {
|
func (s *memorySeries) add(fp clientmodel.Fingerprint, v *metric.SamplePair, persistQueue chan *persistRequest) {
|
||||||
s.mtx.Lock()
|
s.mtx.Lock()
|
||||||
defer s.mtx.Unlock()
|
defer s.mtx.Unlock()
|
||||||
|
|
||||||
|
@ -148,8 +148,6 @@ func (s *memorySeries) add(v *metric.SamplePair, persistQueue chan *persistReque
|
||||||
|
|
||||||
s.head().chunk = chunks[0]
|
s.head().chunk = chunks[0]
|
||||||
if len(chunks) > 1 {
|
if len(chunks) > 1 {
|
||||||
fp := s.metric.Fingerprint()
|
|
||||||
|
|
||||||
queuePersist := func(cd *chunkDesc) {
|
queuePersist := func(cd *chunkDesc) {
|
||||||
persistQueue <- &persistRequest{
|
persistQueue <- &persistRequest{
|
||||||
fingerprint: fp,
|
fingerprint: fp,
|
||||||
|
|
|
@ -98,15 +98,6 @@ type persistRequest struct {
|
||||||
|
|
||||||
// AppendSamples implements Storage.
|
// AppendSamples implements Storage.
|
||||||
func (s *memorySeriesStorage) AppendSamples(samples clientmodel.Samples) {
|
func (s *memorySeriesStorage) AppendSamples(samples clientmodel.Samples) {
|
||||||
/*
|
|
||||||
s.mtx.Lock()
|
|
||||||
defer s.mtx.Unlock()
|
|
||||||
if s.state != storageServing {
|
|
||||||
panic("storage is not serving")
|
|
||||||
}
|
|
||||||
s.mtx.Unlock()
|
|
||||||
*/
|
|
||||||
|
|
||||||
for _, sample := range samples {
|
for _, sample := range samples {
|
||||||
s.appendSample(sample)
|
s.appendSample(sample)
|
||||||
}
|
}
|
||||||
|
@ -118,15 +109,20 @@ func (s *memorySeriesStorage) appendSample(sample *clientmodel.Sample) {
|
||||||
s.mtx.Lock()
|
s.mtx.Lock()
|
||||||
defer s.mtx.Unlock()
|
defer s.mtx.Unlock()
|
||||||
|
|
||||||
series := s.getOrCreateSeries(sample.Metric)
|
if s.state != storageServing {
|
||||||
series.add(&metric.SamplePair{
|
panic("storage is not serving")
|
||||||
|
}
|
||||||
|
|
||||||
|
fp := sample.Metric.Fingerprint()
|
||||||
|
series := s.getOrCreateSeries(fp, sample.Metric)
|
||||||
|
// TODO: Can we release s.mtx here already?
|
||||||
|
series.add(fp, &metric.SamplePair{
|
||||||
Value: sample.Value,
|
Value: sample.Value,
|
||||||
Timestamp: sample.Timestamp,
|
Timestamp: sample.Timestamp,
|
||||||
}, s.persistQueue)
|
}, s.persistQueue)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *memorySeriesStorage) getOrCreateSeries(m clientmodel.Metric) *memorySeries {
|
func (s *memorySeriesStorage) getOrCreateSeries(fp clientmodel.Fingerprint, m clientmodel.Metric) *memorySeries {
|
||||||
fp := m.Fingerprint()
|
|
||||||
series, ok := s.fingerprintToSeries[fp]
|
series, ok := s.fingerprintToSeries[fp]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -185,7 +181,7 @@ func (s *memorySeriesStorage) preloadChunksForRange(fp clientmodel.Fingerprint,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
series = s.getOrCreateSeries(metric)
|
series = s.getOrCreateSeries(fp, metric)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return series.preloadChunksForRange(from, through, s.persistence)
|
return series.preloadChunksForRange(from, through, s.persistence)
|
||||||
|
|
Loading…
Reference in a new issue