This commit is contained in:
James Luck 2025-08-05 14:00:36 +02:00 committed by GitHub
commit cdeeae0ced
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 92 additions and 1 deletions

View File

@ -0,0 +1,87 @@
// Copyright 2021 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 promql
import (
"context"
"runtime"
"testing"
"time"
"github.com/prometheus/common/promslog"
"github.com/prometheus/prometheus/tsdb"
"go.opentelemetry.io/otel"
)
func BenchmarkCountSingleInstance(b *testing.B) {
benchmarkQuery("count(bid_request_count{instance='vad-gp-bac12-1:11108'})", b)
}
func BenchmarkCountAll(b *testing.B) {
benchmarkQuery("count(bid_request_count)", b)
}
func BenchmarkCountSingleInstanceOver1h(b *testing.B) {
benchmarkQuery("count(count_over_time(bid_request_count{instance='vad-gp-bac12-1:11108'}[1h]))", b)
}
func BenchmarkCountAllOver1h(b *testing.B) {
benchmarkQuery("count(count_over_time(bid_request_count[1h]))", b)
}
func benchmarkQuery(query string, b *testing.B) {
l := promslog.NewNopLogger()
// TSDB contains a single production block, containing a high cardinality series (~150K)
db, err := tsdb.Open("/temp/test-tsdb", nil, nil, tsdb.DefaultOptions(), nil)
noErr(err)
// Create engine for querying
otel.Tracer("name").Start(context.Background(), "Run")
for n := 0; n < b.N; n++ {
eng := NewEngine(EngineOpts{
Logger: l,
Reg: nil,
MaxSamples: 50000000,
Timeout: 60 * time.Second,
EnablePerStepStats: true,
})
noErr(err)
q, err := eng.NewInstantQuery(context.Background(), db, &PrometheusQueryOpts{}, query, time.UnixMilli(1688922000001))
noErr(err)
q.Stats().Samples.EnablePerStepStats = true
b.StartTimer()
q.Exec(context.Background())
b.StopTimer()
if n == 0 {
b.ReportMetric(float64(q.Stats().Samples.PeakSamples), "peak_samples")
b.ReportMetric(float64(q.Stats().Samples.TotalSamples), "total_samples")
}
}
var memstats runtime.MemStats
runtime.ReadMemStats(&memstats)
b.ReportMetric(float64(memstats.Sys), "sys_memory")
// Clean up any last resources when done.
err = db.Close()
noErr(err)
}
func noErr(err error) {
if err != nil {
panic(err)
}
}

View File

@ -1477,7 +1477,11 @@ func (r *Reader) lookupSymbol(_ context.Context, o uint32) (string, error) {
if s, ok := r.nameSymbols[o]; ok {
return s, nil
}
return r.symbols.Lookup(o)
s, err := r.symbols.Lookup(o)
if err == nil {
r.nameSymbols[o] = s
}
return s, err
}
// Symbols returns an iterator over the symbols that exist within the index.