-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
70 lines (60 loc) · 1.75 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"flag"
"fmt"
"os"
"time"
"github.com/pkg/profile"
)
type options struct {
engine string
numKeys int
minKeySize int
maxKeySize int
minValueSize int
maxValueSize int
concurrency int
path string
compact bool
profileMode string
}
func main() {
var opts options
flag.StringVar(&opts.engine, "e", "", "database engine name.")
flag.IntVar(&opts.numKeys, "n", 100000, "number of keys")
flag.IntVar(&opts.minKeySize, "mink", 16, "minimum key size")
flag.IntVar(&opts.maxKeySize, "maxk", 64, "maximum key size")
flag.IntVar(&opts.minValueSize, "minv", 128, "minimum value size")
flag.IntVar(&opts.maxValueSize, "maxv", 512, "maximum value size")
flag.IntVar(&opts.concurrency, "c", 1, "number of concurrent goroutines")
flag.StringVar(&opts.path, "p", "", "database path")
flag.BoolVar(&opts.compact, "compact", false, "write keys twice and run compaction after")
flag.StringVar(&opts.profileMode, "profile", "", "enable profile. cpu, mem, block or mutex")
flag.Parse()
if opts.maxKeySize < opts.minKeySize {
opts.maxKeySize = opts.minKeySize
}
if opts.maxValueSize < opts.minValueSize {
opts.maxValueSize = opts.minValueSize
}
if opts.path == "" {
flag.Usage()
return
}
switch opts.profileMode {
case "cpu":
defer profile.Start(profile.CPUProfile).Stop()
case "mem":
defer profile.Start(profile.MemProfile).Stop()
case "block":
defer profile.Start(profile.BlockProfile).Stop()
case "mutex":
defer profile.Start(profile.MutexProfile).Stop()
}
peakSysMem, cancelMon := monitorMemory(time.Millisecond * 100)
if err := benchmark(opts); err != nil {
fmt.Fprintf(os.Stderr, "error running benchmark: %v\n", err)
}
cancelMon()
fmt.Printf("peak sys mem: %s\n", byteSize(*peakSysMem))
}