Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new bench target 'bench-fast' #297

Closed
wants to merge 11 commits into from
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,29 @@ benchmarks:
.PHONY: bench-old
bench-old: benchmarks
@echo "Benchmarking old engine"
@go test ./... -bench 'BenchmarkRangeQuery/.*/old_engine' -run none -count 5 | sed -u 's/\/old_engine//' > benchmarks/old.out
@go test ./... -bench 'BenchmarkRangeQuery/slow/.*/old_engine' -run none -count 5 | sed -u 's/\/old_engine//' > benchmarks/old.out
@go test ./... -bench 'BenchmarkNativeHistograms/.*/old_engine' -run none -count 5 | sed -u 's/\/old_engine//' >> benchmarks/old.out

.PHONY: bench-new
bench-new: benchmarks
@echo "Benchmarking new engine"
@go test ./... -bench 'BenchmarkRangeQuery/.*/new_engine' -run none -count 5 | sed -u 's/\/new_engine//' > benchmarks/new.out
@go test ./... -bench 'BenchmarkRangeQuery/slow/.*/new_engine' -run none -count 5 | sed -u 's/\/new_engine//' > benchmarks/new.out
@go test ./... -bench 'BenchmarkNativeHistograms/.*/new_engine' -run none -count 5 | sed -u 's/\/new_engine//' >> benchmarks/new.out

.PHONY: benchmark
benchmark: bench-old bench-new
@benchstat benchmarks/old.out benchmarks/new.out

.PHONY : bench-fast
bench-fast: benchmarks
@echo "Benchmarking old engine"
@go test ./engine -bench 'BenchmarkRangeQuery/fast/.*/old_engine' -run none -count 5 -short | sed -u 's/\/old_engine//' > benchmarks/old.out
@go test ./engine -bench 'BenchmarkNativeHistograms/.*/old_engine' -run none -count 5 | sed -u 's/\/old_engine//' >> benchmarks/old.out
@echo "Benchmarking new engine"
@go test ./engine -bench 'BenchmarkRangeQuery/fast/.*/new_engine' -run none -count 5 -short | sed -u 's/\/new_engine//' > benchmarks/new.out
@go test ./engine -bench 'BenchmarkNativeHistograms/.*/new_engine' -run none -count 5 | sed -u 's/\/new_engine//' >> benchmarks/new.out
@benchstat benchmarks/old.out benchmarks/new.out

.PHONY: sync-parser
sync-parser:
@echo "Cleaning existing directories"
Expand Down
122 changes: 88 additions & 34 deletions engine/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,9 @@ func BenchmarkSingleQuery(b *testing.B) {

func BenchmarkRangeQuery(b *testing.B) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just use tesitng.Short() for this?

samplesPerHour := 60 * 2
sixHourDataset := setupStorage(b, 1000, 3, 6*samplesPerHour)
defer sixHourDataset.Close()

largeSixHourDataset := setupStorage(b, 10000, 10, 6*samplesPerHour)
defer largeSixHourDataset.Close()

sevenDaysAndTwoHoursDataset := setupStorage(b, 1000, 3, (7*24+2)*samplesPerHour)
defer sevenDaysAndTwoHoursDataset.Close()
var sixHourDataset *promql.Test
var largeSixHourDataset *promql.Test
var sevenDaysAndTwoHoursDataset *promql.Test

start := time.Unix(0, 0)
end := start.Add(2 * time.Hour)
Expand Down Expand Up @@ -272,41 +267,100 @@ func BenchmarkRangeQuery(b *testing.B) {
},
}

for _, tc := range cases {
b.Run(tc.name, func(b *testing.B) {
b.ReportAllocs()
b.Run("old_engine", func(b *testing.B) {
opts := promql.EngineOpts{
Logger: nil,
Reg: nil,
MaxSamples: 50000000,
Timeout: 100 * time.Second,
EnableAtModifier: true,
EnableNegativeOffset: true,
}
engine := promql.NewEngine(opts)
b.Run("fast", func(b *testing.B) {
sixHourDataset = setupStorage(b, 1000, 3, 6*samplesPerHour)
defer sixHourDataset.Close()

for _, tc := range cases {
b.Run(tc.name , func(b *testing.B) {
if testing.Short() && (tc.test == largeSixHourDataset || tc.test == sevenDaysAndTwoHoursDataset) {
b.Skip()
}
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
qry, err := engine.NewRangeQuery(tc.test.Context(), tc.test.Queryable(), nil, tc.query, start, end, step)
testutil.Ok(b, err)
b.Run("old_engine", func(b *testing.B) {
opts := promql.EngineOpts{
Logger: nil,
Reg: nil,
MaxSamples: 50000000,
Timeout: 100 * time.Second,
EnableAtModifier: true,
EnableNegativeOffset: true,
}
engine := promql.NewEngine(opts)

oldResult := qry.Exec(tc.test.Context())
testutil.Ok(b, oldResult.Err)
}
b.ResetTimer()
b.ReportAllocs()

for i := 0; i < b.N; i++ {
qry, err := engine.NewRangeQuery(tc.test.Context(), tc.test.Queryable(), nil, tc.query, start, end, step)
testutil.Ok(b, err)

oldResult := qry.Exec(tc.test.Context())
testutil.Ok(b, oldResult.Err)
}
})
b.Run("new_engine", func(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()

for i := 0; i < b.N; i++ {
newResult := executeRangeQuery(b, tc.query, tc.test, start, end, step)
testutil.Ok(b, newResult.Err)
}
})
})
b.Run("new_engine", func(b *testing.B) {
}
})

b.Run("slow", func(b *testing.B) {
largeSixHourDataset = setupStorage(b, 10000, 10, 6*samplesPerHour)
defer largeSixHourDataset.Close()

sevenDaysAndTwoHoursDataset = setupStorage(b, 1000, 3, (7*24+2)*samplesPerHour)
defer sevenDaysAndTwoHoursDataset.Close()

sixHourDataset = setupStorage(b, 1000, 3, 6*samplesPerHour)
defer sixHourDataset.Close()

for _, tc := range cases {
b.Run(tc.name, func(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()
b.Run("old_engine", func(b *testing.B) {
opts := promql.EngineOpts{
Logger: nil,
Reg: nil,
MaxSamples: 50000000,
Timeout: 100 * time.Second,
EnableAtModifier: true,
EnableNegativeOffset: true,
}
engine := promql.NewEngine(opts)

for i := 0; i < b.N; i++ {
newResult := executeRangeQuery(b, tc.query, tc.test, start, end, step)
testutil.Ok(b, newResult.Err)
}
b.ResetTimer()
b.ReportAllocs()

for i := 0; i < b.N; i++ {
qry, err := engine.NewRangeQuery(tc.test.Context(), tc.test.Queryable(), nil, tc.query, start, end, step)
testutil.Ok(b, err)

oldResult := qry.Exec(tc.test.Context())
testutil.Ok(b, oldResult.Err)
}
})
b.Run("new_engine", func(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()

for i := 0; i < b.N; i++ {
newResult := executeRangeQuery(b, tc.query, tc.test, start, end, step)
testutil.Ok(b, newResult.Err)
}
})
})
})
}
}
})
}

func BenchmarkNativeHistograms(b *testing.B) {
Expand Down
31 changes: 31 additions & 0 deletions engine/distributed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import (
"testing"
"time"

"github.com/efficientgo/core/errors"
"github.com/efficientgo/core/testutil"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/promql"
"github.com/prometheus/prometheus/storage"

"github.com/thanos-io/promql-engine/api"
"github.com/thanos-io/promql-engine/engine"
Expand Down Expand Up @@ -329,3 +331,32 @@ func TestDistributedAggregations(t *testing.T) {
}
}
}

func TestDistributedEngineWarnings(t *testing.T) {
querier := &storage.MockQueryable{
MockQuerier: &storage.MockQuerier{
SelectMockFunction: func(sortSeries bool, hints *storage.SelectHints, matchers ...*labels.Matcher) storage.SeriesSet {
return newWarningsSeriesSet(storage.Warnings{errors.New("test warning")})
},
},
}

opts := engine.Opts{
EngineOpts: promql.EngineOpts{
MaxSamples: math.MaxInt64,
Timeout: 1 * time.Minute,
},
}
remote := engine.NewRemoteEngine(opts, querier, math.MinInt64, math.MaxInt64, nil)
ng := engine.NewDistributedEngine(opts, api.NewStaticEndpoints([]api.RemoteEngine{remote}))
var (
start = time.UnixMilli(0)
end = time.UnixMilli(600)
step = 30 * time.Second
)
q, err := ng.NewRangeQuery(context.Background(), nil, nil, "test", start, end, step)
testutil.Ok(t, err)

res := q.Exec(context.Background())
testutil.Equals(t, 1, len(res.Warnings))
}
Loading