gen

package
v0.2.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bytes

func Bytes(seed, length uint64) []byte

Bytes generates a byte slice of length length from seed. The byte slice is deterministically generated using the (very fast) xxhash algorithm.

func StoreKeys

func StoreKeys(prefix string, seed, count uint64) ([]string, error)

StoreKeys deterministically generates a set of unique store keys from seed.

func WithGenesis

func WithGenesis() func(*Generator)

WithGenesis sets the generator state to the genesis seed. When the generator is created, it will sync to genesis state. The benchmark client needs to do this so that it can generate meaningful tx operations.

func WithSeed

func WithSeed(seed uint64) func(*Generator)

WithSeed sets the seed for the generator.

Types

type Generator

type Generator struct {
	Options
	// contains filtered or unexported fields
}

Generator generates operations for a benchmark transaction. The generator is stateful, keeping track of which keys have been inserted so that meaningful gets and deletes can be generated.

func NewGenerator

func NewGenerator(opts Options, f ...opt) *Generator

NewGenerator creates a new generator with the given options.

func (*Generator) Close

func (g *Generator) Close() error

func (*Generator) GenesisSet

func (g *Generator) GenesisSet() iter.Seq[*KV]

GenesisSet returns a sequence of key-value pairs for the genesis state. It is called by the server during InitGenesis to generate and set the initial state. The client uses WithGenesis to sync to the genesis state.

func (*Generator) Load

func (g *Generator) Load() error

Load loads the generator state from disk.

func (*Generator) Next

func (g *Generator) Next() (uint64, *benchmark.Op, error)

Next generates the next benchmark operation. The operation is one of insert, update, get, or delete. The tx client calls this function to deterministically generate the next operation.

func (*Generator) NormUint64

func (g *Generator) NormUint64(mean, stdDev uint64) uint64

NormUint64 returns a random uint64 with a normal distribution.

func (*Generator) UintN

func (g *Generator) UintN(n uint64) uint64

UintN returns a random uint64 in the range [0, n).

type KV

type KV struct {
	StoreKey uint64
	Key      Payload
	Value    Payload
}

KV is a key-value pair with a store key.

type Options

type Options struct {
	*module.GeneratorParams
	// HomeDir is for reading/writing state
	HomeDir string

	InsertWeight float64
	UpdateWeight float64
	GetWeight    float64
	DeleteWeight float64
}

Options is the configuration for the generator.

type Payload

type Payload [2]uint64

Payload is a 2-tuple of seed and length. A seed is uint64 which is used to generate a byte slice of size length.

func NewPayload

func NewPayload(seed, length uint64) Payload

func (Payload) Bytes

func (p Payload) Bytes() []byte

Bytes returns the byte slice generated from the seed and length. The underlying byte slice is deterministically generated using the (very fast) xxhash algorithm.

func (Payload) Length

func (p Payload) Length() uint64

Length returns the length in the payload.

func (Payload) Seed

func (p Payload) Seed() uint64

Seed returns the seed in the payload.

func (Payload) String

func (p Payload) String() string

type State

type State struct {
	Src interface {
		rand.Source
		encoding.BinaryMarshaler
		encoding.BinaryUnmarshaler
	}
	Keys [][]Payload
}

State is the state of the generator. It can be marshaled and unmarshaled to/from a binary format.

func (*State) Marshal

func (s *State) Marshal(w io.Writer) error

Marshal writes the state to w.

func (*State) Unmarshal

func (s *State) Unmarshal(r io.Reader) error

Unmarshal reads the state from r.

Jump to

Keyboard shortcuts

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