-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
72 lines (59 loc) · 1.64 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
71
72
package main
import (
"encoding/json"
"flag"
"io/ioutil"
"log"
"os"
"time"
)
// MemcacheConfig holds the details of the memcached instance
type MemcacheConfig struct {
Addresses []string `json:"addresses"`
//MaxRetriesOnError int `json:"max-retries"`
}
// Config holds the configuration of the load testing tool
type Config struct {
MemcacheSrc MemcacheConfig `json:"memcache_src"`
MemcacheDest MemcacheConfig `json:"memcache_dest"`
NThreads int `json:"n_threads"`
Move bool `json:"move"`
}
func main() {
flags := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
configuration := flags.String("conf", "", "path to configuration file")
flags.Parse(os.Args[1:])
if "" == *configuration {
log.Println("Usage: ", os.Args[0], "-conf=<file.conf>")
flag.PrintDefaults()
os.Exit(2)
}
conf := readConfig(*configuration)
timestart := time.Now()
log.Println("START:", timestart.String())
summary := StatsSummary{Title: "GLOBAL"}
for _, srcAddr := range conf.MemcacheSrc.Addresses {
// read keys directly from the source memcache instance
proc := NewServerProcessor(srcAddr, conf.MemcacheDest.Addresses, conf.Move)
proc.Run()
st := proc.GetStatsSummary()
st.Print()
summary.Merge(st)
}
summary.Print()
}
// readConfig reads the configuration from file into an Config structure
func readConfig(filename string) Config {
b, err := ioutil.ReadFile(filename)
if err != nil {
log.Println("Cannot read configuration file", filename)
os.Exit(1)
}
var conf Config
err = json.Unmarshal(b, &conf)
if err != nil {
log.Println("Cannot parse configuration file:", err)
os.Exit(1)
}
return conf
}