mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-10 07:34:04 -08:00
59d02b5ef0
* tsdb: Block Head GC till pending readers are done reading Signed-off-by: Ganesh Vernekar <ganeshvern@gmail.com> * Fix review comments Signed-off-by: Ganesh Vernekar <ganeshvern@gmail.com> * Fix review comments 2 Signed-off-by: Ganesh Vernekar <ganeshvern@gmail.com> * Fix the exclusiveness of maxt in WaitForPendingReadersInTimeRange Signed-off-by: Ganesh Vernekar <ganeshvern@gmail.com>
101 lines
2 KiB
Go
101 lines
2 KiB
Go
// Copyright 2020 The Prometheus Authors
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package tsdb
|
|
|
|
import (
|
|
"math"
|
|
"strconv"
|
|
"sync"
|
|
"testing"
|
|
)
|
|
|
|
func BenchmarkIsolation(b *testing.B) {
|
|
for _, goroutines := range []int{10, 100, 1000, 10000} {
|
|
b.Run(strconv.Itoa(goroutines), func(b *testing.B) {
|
|
iso := newIsolation()
|
|
|
|
wg := sync.WaitGroup{}
|
|
start := make(chan struct{})
|
|
|
|
for g := 0; g < goroutines; g++ {
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
defer wg.Done()
|
|
<-start
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
appendID, _ := iso.newAppendID()
|
|
|
|
iso.closeAppend(appendID)
|
|
}
|
|
}()
|
|
}
|
|
|
|
b.ResetTimer()
|
|
close(start)
|
|
wg.Wait()
|
|
})
|
|
}
|
|
}
|
|
|
|
func BenchmarkIsolationWithState(b *testing.B) {
|
|
for _, goroutines := range []int{10, 100, 1000, 10000} {
|
|
b.Run(strconv.Itoa(goroutines), func(b *testing.B) {
|
|
iso := newIsolation()
|
|
|
|
wg := sync.WaitGroup{}
|
|
start := make(chan struct{})
|
|
|
|
for g := 0; g < goroutines; g++ {
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
defer wg.Done()
|
|
<-start
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
appendID, _ := iso.newAppendID()
|
|
|
|
iso.closeAppend(appendID)
|
|
}
|
|
}()
|
|
}
|
|
|
|
readers := goroutines / 100
|
|
if readers == 0 {
|
|
readers++
|
|
}
|
|
|
|
for g := 0; g < readers; g++ {
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
defer wg.Done()
|
|
<-start
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
s := iso.State(math.MinInt64, math.MaxInt64)
|
|
s.Close()
|
|
}
|
|
}()
|
|
}
|
|
|
|
b.ResetTimer()
|
|
close(start)
|
|
wg.Wait()
|
|
})
|
|
}
|
|
}
|