leveldbbench

package
v0.1.32 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2023 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LevelDBBenchCmd = &cobra.Command{
	Use:   "leveldbbench [flags]",
	Short: "Perform a level db benchmark",
	Long:  usage,
	RunE: func(cmd *cobra.Command, args []string) error {
		log.Info().Msg("Starting level db test")
		db, err := leveldb.OpenFile(*dbPath, &opt.Options{
			Filter:                 filter.NewBloomFilter(10),
			DisableSeeksCompaction: true,
			OpenFilesCacheCapacity: *openFilesCacheCapacity,
			BlockCacheCapacity:     *cacheSize / 2 * opt.MiB,
			WriteBuffer:            *cacheSize / 4 * opt.MiB,

			ReadOnly: *readOnly || *fullScan,
		})
		if err != nil {
			return err
		}

		ctx := context.Background()
		wo := opt.WriteOptions{
			NoWriteMerge: *noWriteMerge,
			Sync:         *syncWrites,
		}
		ro := &opt.ReadOptions{
			DontFillCache: *dontFillCache,
		}
		if *readStrict {
			ro.Strict = opt.StrictAll
		} else {
			ro.Strict = opt.DefaultStrict
		}
		if *nilReadOptions {
			ro = nil
		}
		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, db, &wo, ro)
			tr := NewTestResult(start, time.Now(), "full scan", opCount, db)
			tr.ValueDist = valueDist
			trs = append(trs, tr)
			return printSummary(trs)
		}

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

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

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

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

		log.Info().Msg("Close DB")
		err = db.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 LoadTestOperation

type LoadTestOperation int

type RandomKeySeeker

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

func NewRandomKeySeeker

func NewRandomKeySeeker(db *leveldb.DB) *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
	Stats        *leveldb.DBStats
	OpRate       float64
	ValueDist    []uint64
}

func NewTestResult

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

Jump to

Keyboard shortcuts

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