Browse Source

Avoid redundant fingerprint calculation.

Change-Id: Ief8a165dcfa5030226953346ec9dfe4a7787df1f
pull/413/head
Bjoern Rabenstein 10 years ago
parent
commit
aea32b0b4b
  1. 4
      storage/local/series.go
  2. 24
      storage/local/storage.go

4
storage/local/series.go

@ -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()
defer s.mtx.Unlock()
@ -148,8 +148,6 @@ func (s *memorySeries) add(v *metric.SamplePair, persistQueue chan *persistReque
s.head().chunk = chunks[0]
if len(chunks) > 1 {
fp := s.metric.Fingerprint()
queuePersist := func(cd *chunkDesc) {
persistQueue <- &persistRequest{
fingerprint: fp,

24
storage/local/storage.go

@ -98,15 +98,6 @@ type persistRequest struct {
// AppendSamples implements Storage.
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 {
s.appendSample(sample)
}
@ -118,15 +109,20 @@ func (s *memorySeriesStorage) appendSample(sample *clientmodel.Sample) {
s.mtx.Lock()
defer s.mtx.Unlock()
series := s.getOrCreateSeries(sample.Metric)
series.add(&metric.SamplePair{
if s.state != storageServing {
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,
Timestamp: sample.Timestamp,
}, s.persistQueue)
}
func (s *memorySeriesStorage) getOrCreateSeries(m clientmodel.Metric) *memorySeries {
fp := m.Fingerprint()
func (s *memorySeriesStorage) getOrCreateSeries(fp clientmodel.Fingerprint, m clientmodel.Metric) *memorySeries {
series, ok := s.fingerprintToSeries[fp]
if !ok {
@ -185,7 +181,7 @@ func (s *memorySeriesStorage) preloadChunksForRange(fp clientmodel.Fingerprint,
if err != nil {
return nil, err
}
series = s.getOrCreateSeries(metric)
series = s.getOrCreateSeries(fp, metric)
}
}
return series.preloadChunksForRange(from, through, s.persistence)

Loading…
Cancel
Save