Skip to content

Commit

Permalink
Merge #62107
Browse files Browse the repository at this point in the history
62107: sql: introduce BenchmarkSampling r=irfansharif a=irfansharif

Introduce a benchmark to measure the statement sampling overhead.

    $ make bench PKG=./pkg/bench TESTFLAGS='-benchtime=5000x -count 10' \
        BENCHES='BenchmarkSampling' BENCHTIMEOUT=50m > benchmark-sampling.txt
    $ cat benchmark-sampling.txt | grep -v sample_rate=1.0 | sed 's/sample_rate=...//' > old.txt
    $ cat benchmark-sampling.txt | grep -v sample_rate=0.0 | sed 's/sample_rate=...//' > new.txt
    $ benchstat old.txt new.txt

    name                                    old time/op    new time/op    delta
    Sampling/Cockroach//Scan1-24               416µs ± 1%     451µs ± 1%   +8.39%  (p=0.000 n=10+10)
    Sampling/Cockroach//Insert-24              613µs ± 4%     651µs ± 2%   +6.33%  (p=0.000 n=10+10)
    Sampling/MultinodeCockroach//Scan1-24      840µs ± 1%     960µs ± 2%  +14.24%  (p=0.000 n=9+9)
    Sampling/MultinodeCockroach//Insert-24    1.13ms ± 3%    1.20ms ± 2%   +6.56%  (p=0.000 n=10+10)

    name                                    old alloc/op   new alloc/op   delta
    Sampling/Cockroach//Scan1-24              24.4kB ± 1%    42.6kB ± 3%  +74.82%  (p=0.000 n=8+10)
    Sampling/Cockroach//Insert-24             37.6kB ±11%    50.7kB ± 5%  +34.67%  (p=0.000 n=10+10)
    Sampling/MultinodeCockroach//Scan1-24     76.4kB ±20%   112.5kB ± 6%  +47.19%  (p=0.000 n=10+10)
    Sampling/MultinodeCockroach//Insert-24     112kB ±24%     123kB ± 8%   +9.72%  (p=0.035 n=10+10)

    name                                    old allocs/op  new allocs/op  delta
    Sampling/Cockroach//Scan1-24                 254 ± 1%       363 ± 1%  +43.21%  (p=0.000 n=8+9)
    Sampling/Cockroach//Insert-24                299 ± 2%       397 ± 1%  +33.07%  (p=0.000 n=10+10)
    Sampling/MultinodeCockroach//Scan1-24        784 ± 3%      1063 ± 1%  +35.57%  (p=0.000 n=9+9)
    Sampling/MultinodeCockroach//Insert-24       770 ±13%       882 ± 2%  +14.56%  (p=0.000 n=10+9)

Release note: None

Co-authored-by: irfan sharif <[email protected]>
  • Loading branch information
craig[bot] and irfansharif committed Mar 17, 2021
2 parents 7894414 + 4acf26b commit e281854
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions pkg/bench/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,43 @@ func BenchmarkSQL(b *testing.B) {
})
}

// BenchmarkSampling measures the overhead of sampled statements. It also
// reports the memory utilization.
func BenchmarkSampling(b *testing.B) {
skip.UnderShort(b)
defer log.Scope(b).Close(b)

for _, dbFn := range []func(*testing.B, BenchmarkFn){
benchmarkCockroach,
benchmarkMultinodeCockroach,
} {
dbName := runtime.FuncForPC(reflect.ValueOf(dbFn).Pointer()).Name()
dbName = strings.TrimPrefix(dbName, "github.com/cockroachdb/cockroach/pkg/bench.benchmark")

b.Run(dbName, func(b *testing.B) {
dbFn(b, func(b *testing.B, db *sqlutils.SQLRunner) {
for _, sampleRate := range []string{"1.0", "0.0"} {
db.Exec(b, fmt.Sprintf("SET CLUSTER SETTING sql.txn_stats.sample_rate = %s", sampleRate))
b.Run(fmt.Sprintf("sample_rate=%s", sampleRate), func(b *testing.B) {
for _, runFn := range []func(*testing.B, *sqlutils.SQLRunner, int){
runBenchmarkScan1,
runBenchmarkInsert,
} {
fnName := runtime.FuncForPC(reflect.ValueOf(runFn).Pointer()).Name()
fnName = strings.TrimPrefix(fnName, "github.com/cockroachdb/cockroach/pkg/bench.runBenchmark")
b.Run(fnName, func(b *testing.B) {
b.ReportAllocs()

runFn(b, db, 1 /* count */)
})
}
})
}
})
})
}
}

// BenchmarkTracing measures the overhead of always-on tracing. It also reports
// the memory utilization.
//
Expand Down

0 comments on commit e281854

Please sign in to comment.