dbbench

package
v0.1.64 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: AGPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DBBenchCmd = &cobra.Command{
	Use:   "dbbench [flags]",
	Short: "Perform a level/pebble db benchmark",
	Long:  usage,
	RunE: func(cmd *cobra.Command, args []string) error {
		log.Info().Msg("Starting db test")
		var kvdb KeyValueDB
		var err error
		switch *dbMode {
		case "leveldb":
			kvdb, err = NewWrappedLevelDB()
			if err != nil {
				return err
			}
		case "pebbledb":
			kvdb, err = NewWrappedPebbleDB()
			if err != nil {
				return err
			}
		default:
			return fmt.Errorf("the mode %s is not recognized", *dbMode)
		}

		ctx := context.Background()

		var start time.Time
		trs := make([]*TestResult, 0)

		sequentialWritesDesc := "random"
		if *sequentialWrites {
			sequentialWritesDesc = "sequential"
		}
		sequentialReadsDesc := "random"
		if *sequentialReads {
			sequentialReadsDesc = "sequential"
		}

		if *fullScan {
			start = time.Now()
			opCount, valueDist := runFullScan(ctx, kvdb)
			tr := NewTestResult(start, time.Now(), "full scan", opCount)
			tr.ValueDist = valueDist
			trs = append(trs, tr)
			return printSummary(trs)
		}

		if !*readOnly {
			start = time.Now()
			writeData(ctx, kvdb, 0, *writeLimit, *sequentialWrites)
			trs = append(trs, NewTestResult(start, time.Now(), fmt.Sprintf("initial %s write", sequentialWritesDesc), *writeLimit))

			for i := 0; i < int(*overwriteCount); i += 1 {
				start = time.Now()
				writeData(ctx, kvdb, 0, *writeLimit, *sequentialWrites)
				trs = append(trs, NewTestResult(start, time.Now(), fmt.Sprintf("%s overwrite %d", sequentialWritesDesc, i), *writeLimit))
			}

			start = time.Now()
			runFullCompact(ctx, kvdb)
			trs = append(trs, NewTestResult(start, time.Now(), "compaction", 1))
		}

		if *sequentialReads {
			start = time.Now()
			readSeq(ctx, kvdb, *readLimit)
			trs = append(trs, NewTestResult(start, time.Now(), fmt.Sprintf("%s read", sequentialReadsDesc), *readLimit))
		} else {
			start = time.Now()
			readRandom(ctx, kvdb, *readLimit)
			trs = append(trs, NewTestResult(start, time.Now(), fmt.Sprintf("%s read", sequentialWritesDesc), *readLimit))
		}

		log.Info().Msg("Close DB")
		err = kvdb.Close()
		if err != nil {
			log.Error().Err(err).Msg("Error while closing db")
		}

		return printSummary(trs)
	},
	Args: func(cmd *cobra.Command, args []string) error {
		var err error
		sizeDistribution, err = parseRawSizeDistribution(*rawSizeDistribution)
		if err != nil {
			return err
		}
		if *keySize > 64 {
			return fmt.Errorf(" max supported key size is 64 bytes. %d is too big", *keySize)
		}
		return nil
	},
}

Functions

This section is empty.

Types

type IODistribution

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

func NewIODistribution

func NewIODistribution(ranges []IORange) (*IODistribution, error)

func (*IODistribution) GetSizeSample

func (i *IODistribution) GetSizeSample() uint64

GetSizeSample will return an IO size in accordance with the probability distribution

type IORange

type IORange struct {
	StartRange int
	EndRange   int
	Frequency  int
}

func (*IORange) Validate

func (i *IORange) Validate() error

type KeyValueDB

type KeyValueDB interface {
	Close() error
	Compact() error
	NewIterator() iterator.Iterator
	Get([]byte) ([]byte, error)
	Put([]byte, []byte) error
}

KeyValueDB directly exposes the necessary methods of leveldb.DB that we need to run the test so that they can be implemented by other KV stores

type LevelDBWrapper

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

func NewWrappedLevelDB

func NewWrappedLevelDB() (*LevelDBWrapper, error)

func (*LevelDBWrapper) Close

func (l *LevelDBWrapper) Close() error

func (*LevelDBWrapper) Compact

func (l *LevelDBWrapper) Compact() error

func (*LevelDBWrapper) Get

func (l *LevelDBWrapper) Get(key []byte) ([]byte, error)

func (*LevelDBWrapper) NewIterator

func (l *LevelDBWrapper) NewIterator() iterator.Iterator

func (*LevelDBWrapper) Put

func (l *LevelDBWrapper) Put(key []byte, value []byte) error

type LoadTestOperation

type LoadTestOperation int

type PebbleDBWrapper

type PebbleDBWrapper struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewWrappedPebbleDB

func NewWrappedPebbleDB() (*PebbleDBWrapper, error)

func (*PebbleDBWrapper) Close

func (p *PebbleDBWrapper) Close() error

func (*PebbleDBWrapper) Compact

func (p *PebbleDBWrapper) Compact() error

func (*PebbleDBWrapper) Get

func (p *PebbleDBWrapper) Get(key []byte) ([]byte, error)

func (*PebbleDBWrapper) NewIterator

func (p *PebbleDBWrapper) NewIterator() iterator.Iterator

func (*PebbleDBWrapper) Put

func (p *PebbleDBWrapper) Put(key []byte, value []byte) error

type RandomKeySeeker

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

func NewRandomKeySeeker

func NewRandomKeySeeker(db KeyValueDB) *RandomKeySeeker

func (*RandomKeySeeker) Key

func (r *RandomKeySeeker) Key() []byte

type TestResult

type TestResult struct {
	StartTime    time.Time
	EndTime      time.Time
	TestDuration time.Duration
	Description  string
	OpCount      uint64
	OpRate       float64
	ValueDist    []uint64
}

func NewTestResult

func NewTestResult(startTime, endTime time.Time, desc string, opCount uint64) *TestResult

type WrappedPebbleIterator

type WrappedPebbleIterator struct {
	*pebble.Iterator
	*sync.Mutex
}

func (*WrappedPebbleIterator) Release

func (w *WrappedPebbleIterator) Release()

func (*WrappedPebbleIterator) Seek

func (w *WrappedPebbleIterator) Seek(key []byte) bool

func (*WrappedPebbleIterator) SetReleaser

func (w *WrappedPebbleIterator) SetReleaser(releaser util.Releaser)

Jump to

Keyboard shortcuts

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