bbolt icon indicating copy to clipboard operation
bbolt copied to clipboard

Migrate bench to a cobra style command

Open ivanvc opened this issue 2 years ago • 6 comments

Migrates bbolt bench to a cobra-style command. I made some changes to clean up the code a bit.

  1. Even though the functions in the original code belonged to a struct, most of the arguments were being forwarded to the nested functions, so I changed the struct to store these values and have them available in the functions
  2. Even though there was a read-mode option, the only available mode was sequential (seq), So I removed this option. https://github.com/etcd-io/bbolt/blob/019c34e51f940334d41a0c1cc1a50e7ba6d0f782/cmd/bbolt/main.go#L1313-L1323 While having these changes, the output of the command and the behavior remain the same.

Old run:

$ bbolt bench -write-mode rnd-nest -batch-size 500 
starting write benchmark.
Starting write iteration 0
Finished write iteration 0
Starting write iteration 500
Finished write iteration 500
starting read benchmark.
# Write 1000(ops)       1.53224ms       (1.532µs/op)    (652741 op/sec)
# Read  57310000(ops)   1.000015207s    (17ns/op)       (58823529 op/sec)

New:

$ bbolt bench --write-mode rnd-nest --batch-size 500 
starting write benchmark.
Starting write iteration 0
Finished write iteration 0
Starting write iteration 500
Finished write iteration 500
starting read benchmark.
# Write 1000(ops)       1.570807ms      (1.57µs/op)     (636942 op/sec)
# Read  50249000(ops)   1.000010436s    (19ns/op)       (52631578 op/sec)

Old:

$ bbolt bench -h
Usage:
  -batch-size int
    
  -blockprofile string
    
  -count int
         (default 1000)
  -cpuprofile string
    
  -fill-percent float
         (default 0.5)
  -key-size int
         (default 8)
  -memprofile string
    
  -no-sync
    
  -path string
    
  -profile-mode string
         (default "rw")
  -read-mode string
         (default "seq")
  -value-size int
         (default 32)
  -work
    
  -write-mode string
         (default "seq")
flag: help requested
exit status 1

New:

$ bbolt bench -h
run synthetic benchmark against bbolt

Usage:
  bbolt bench [flags]

Flags:
      --batch-size uint32      the step size for each iteration, if not provided iteration size is used, it needs to be evenly divided by the iteration count (count)
      --blockprofile string   output file for the pprof block profile
      --count uint32           the number of iterations (default 1000)
      --cpuprofile string     output file for the pprof CPU profile
      --fill-percent float     the percentage that split pages are filled (default 0.5)
  -h, --help                   help for bench
      --key-size int           the size for the key, from the key value insertion (default 8)
      --memprofile string     output file for the pprof memoery profile
      --no-sync                skip fsync() calls after each commit
      --path string            path to the database file
      --profile-mode string    the profile mode to execute, valid modes are r, w and rw (default "rw")
      --value-size int         the size for the value, from the key value insertion (default 32)
      --work                   if set, the database path won't be removed after the execution
      --write-mode string      the write mode, valid values are seq, rnd, seq-nest and rnd-nest (default "seq")

Relates to #472.

ivanvc avatar Jan 24 '24 06:01 ivanvc

A quick question, @ivanvc is there any user-facing change? If there isn't such change, then we should be good to merge this PR.

ahrtr avatar Mar 27 '24 16:03 ahrtr

@ahrtr, I deleted the -read-mode flag, as the only option available was seq. Providing any other value halted the execution.

However, changing from built-in Go flags to Cobra flags isn't backward compatible, as Go flags aren't POSIX compliant.

ivanvc avatar Mar 27 '24 16:03 ivanvc

OK, thanks for the clarification. Then let's merge this PR once we cut release-1.4 branch.

ahrtr avatar Mar 27 '24 16:03 ahrtr

Drafting because of #711

ivanvc avatar Apr 11 '24 20:04 ivanvc