MCPcopy
hub / github.com/etcd-io/bbolt / runReadsRandom

Function runReadsRandom

cmd/bbolt/command/command_bench.go:479–516  ·  view source on GitHub ↗
(cmd *cobra.Command, db *bolt.DB, options *benchOptions, keys []nestedKey, results *benchResults)

Source from the content-addressed store, hash-verified

477}
478
479func runReadsRandom(cmd *cobra.Command, db *bolt.DB, options *benchOptions, keys []nestedKey, results *benchResults) error {
480 return db.View(func(tx *bolt.Tx) error {
481 t := time.Now()
482
483 for {
484 numReads := int64(0)
485 err := func() error {
486 defer func() { results.addCompletedOps(numReads) }()
487
488 b := tx.Bucket(benchBucketName)
489 for _, key := range keys {
490 v := b.Get(key.key)
491 numReads++
492 if v == nil {
493 return ErrInvalidValue
494 }
495 }
496
497 return nil
498 }()
499
500 if err != nil {
501 return err
502 }
503
504 if options.writeMode == "seq" && numReads != options.iterations {
505 return fmt.Errorf("read seq: iter mismatch: expected %d, got %d", options.iterations, numReads)
506 }
507
508 // Make sure we do this for at least a second.
509 if time.Since(t) >= time.Second {
510 break
511 }
512 }
513
514 return nil
515 })
516}
517
518func runReadsSequentialNested(cmd *cobra.Command, db *bolt.DB, options *benchOptions, results *benchResults) error {
519 return db.View(func(tx *bolt.Tx) error {

Callers 1

runReadsFunction · 0.85

Calls 5

ViewMethod · 0.80
addCompletedOpsMethod · 0.80
ErrorfMethod · 0.65
BucketMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected