| 477 | } |
| 478 | |
| 479 | func 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 | |
| 518 | func runReadsSequentialNested(cmd *cobra.Command, db *bolt.DB, options *benchOptions, results *benchResults) error { |
| 519 | return db.View(func(tx *bolt.Tx) error { |