spannerbench

package module
v0.0.0-...-037b489 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

README

spannerbench logo

A Google Cloud Spanner transaction benchmarking framework.

See examples/helloworld for an example.

Usage

$ go run examples/helloworld/main.go
BenchmarkReadOnly
Latency histogram:
  65.772419ms : ■ (1)
  310.325496ms: ■■■■■■■■■■■■■■■■■■■■ (37)
  554.878574ms: ■■■ (6)
  799.431651ms: ■■ (3)
  1.043984729s: ■ (1)
  1.288537807s: ■ (2)

Benchmark
Latency histogram:
  101.510159ms: ■ (1)
  355.964311ms: ■■■■■■■■■■■■■■■■■■■■ (46)
  610.418464ms: ■ (2)
  864.872616ms:
  1.119326769s:
  1.373780922s: ■ (1)

Notes

  • The framework only reports the client-perceived latency at the moment.
  • The benchmarks are run sequentially, concurrency support is in the roadmap but is not implemented yet.
  • Note timestamp bound support is work in progress.
  • Framework can warm-up the sessions before starting to benchmark. This improvement is in the roadmap.

Disclaimer

This is not an official Google product.

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

func Benchmark

func Benchmark(db string, fn ...func(b *B))

Benchmark starts the benchmarks. Provide the full-identifier of the Google Cloud Spanner database as db.

Types

type B

type B struct {
	// contains filtered or unexported fields
}

B represents a benchmark. Use Benchmark function to run benchmarks.

func (*B) ExactStaleness

func (b *B) ExactStaleness(d time.Duration)

ExactStaleness represents the exact staleness in reads. It will be ignored for read-write transactions.

func (*B) MaxStaleness

func (b *B) MaxStaleness(d time.Duration)

MaxStaleness sets the max staleness in reads It will be ignored for read-write transactions.

func (*B) N

func (b *B) N(n int)

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.

Directories

Path Synopsis
examples
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL