Documentation ¶
Overview ¶
Package spannerbench provides a benchmarking framework for Google Cloud Spanner.
Example ¶
package main import ( "time" "cloud.google.com/go/spanner" "github.com/rakyll/spannerbench" ) func main() { // import "cloud.google.com/go/spanner" // import "github.com/rakyll/spannerbench" benchmarkReadOnly := func(b *spannerbench.B) { b.N(100) // Runs for 100 times. b.MaxStaleness(500 * time.Millisecond) b.RunReadOnly(func(tx *spanner.ReadOnlyTransaction) error { // TODO: Use tx to run queries. return nil }) } benchmarkReadWrite := func(b *spannerbench.B) { b.N(50) // Runs for 50 times. b.Run(func(tx *spanner.ReadWriteTransaction) error { // TODO: Use tx to run queries. return nil }) } spannerbench.Benchmark( "projects/YOUR_PROJECT/instances/YOUR_INSTANCE/databases/YOUR_DB", benchmarkReadOnly, benchmarkReadWrite, ) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type B ¶
type B struct {
// contains filtered or unexported fields
}
B represents a benchmark. Use Benchmark function to run benchmarks.
func (*B) ExactStaleness ¶
ExactStaleness represents the exact staleness in reads. It will be ignored for read-write transactions.
func (*B) MaxStaleness ¶
MaxStaleness sets the max staleness in reads It will be ignored for read-write transactions.
func (*B) N ¶
N sets the number of times a benchmarks will be run. If not set, default value (20) is used.
func (*B) Run ¶
func (b *B) Run(fn func(tx *spanner.ReadWriteTransaction) error)
Run runs read-write transaction benchmarks. It starts a read-write transaction and calls fn. The benchmark will be repeated for a number of times and results will be printed.
Run is not safe for concurrent usage. Don't reuse this benchmark once you call Run.
func (*B) RunReadOnly ¶
func (b *B) RunReadOnly(fn func(tx *spanner.ReadOnlyTransaction) error)
RunReadOnly runs readonly transaction benchmarks. It starts a read-only transaction and calls fn. The benchmark will be repeated for a number of times and results will be printed.
Run is not safe for concurrent usage. Don't reuse this benchmark once you call RunReadOnly.