2020-06-03 20:09:05 +02:00
// 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 (
2021-07-20 14:17:20 +05:30
"math"
2020-06-03 20:09:05 +02:00
"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 ) {
2021-11-19 15:41:32 +05:30
iso := newIsolation ( false )
2020-06-03 20:09:05 +02:00
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 ++ {
2021-07-07 14:28:20 +01:00
appendID , _ := iso . newAppendID ( )
2020-06-03 20:09:05 +02:00
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 ) {
2021-11-19 15:41:32 +05:30
iso := newIsolation ( false )
2020-06-03 20:09:05 +02:00
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 ++ {
2021-07-07 14:28:20 +01:00
appendID , _ := iso . newAppendID ( )
2020-06-03 20:09:05 +02:00
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 ++ {
2021-07-20 14:17:20 +05:30
s := iso . State ( math . MinInt64 , math . MaxInt64 )
2020-06-03 20:09:05 +02:00
s . Close ( )
}
} ( )
}
b . ResetTimer ( )
close ( start )
wg . Wait ( )
} )
}
}