-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
113 lines (90 loc) · 2.97 KB
/
main.go
File metadata and controls
113 lines (90 loc) · 2.97 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package main
import (
"encoding/json"
"fmt"
"log"
"os"
"strconv"
"strings"
"runtime/debug"
// "runtime/pprof"
// "time"
"github.com/alanwang67/session_semantics/client"
"github.com/alanwang67/session_semantics/protocol"
"github.com/alanwang67/session_semantics/server"
)
func processAddressString(address string, n uint64) string {
l := strings.Split(address, `:`)
i, _ := strconv.ParseUint(l[1], 10, 64)
return l[0] + ":" + (strconv.Itoa(int(i + n)))
}
func main() {
debug.SetGCPercent(-1)
// fmt.Println("We have disabled the GC!")
// f, _ := os.Create("cpu.pprof" + os.Args[2] + os.Args[3])
// pprof.StartCPUProfile(f)
// defer pprof.StopCPUProfile()
config, _ := os.ReadFile("config.json")
portOffSet, _ := strconv.ParseUint(os.Args[1], 10, 64)
var data map[string]interface{}
json.Unmarshal(config, &data)
servers := make([]*protocol.Connection, len(data["servers"].([]interface{})))
for i, s := range data["servers"].([]interface{}) {
conn, _ := s.(map[string]interface{})
network, _ := conn["network"].(string)
address, _ := conn["address"].(string)
servers[i] = &protocol.Connection{
Network: network,
Address: processAddressString(address, portOffSet),
}
}
switch os.Args[2] {
case "client":
fileLocation := os.Args[3]
clientConfig, _ := os.ReadFile(fileLocation)
var data map[string]interface{}
json.Unmarshal(clientConfig, &data)
threads, _ := strconv.ParseUint(os.Args[4], 10, 64)
time, _ := strconv.ParseUint(os.Args[5], 10, 64)
sessionSemantic, _ := strconv.ParseUint(os.Args[6], 10, 64)
workload, _ := strconv.ParseUint(os.Args[7], 10, 64)
switchServer := uint64(data["SwitchServer"].(float64))
primaryBackUpRoundRobin := data["PrimaryBackUpRoundRobin"].(bool)
primaryBackupRandom := data["PrimaryBackupRandom"].(bool)
gossipRandom := data["GossipRandom"].(bool)
pinnedRoundRobin := data["PinnedRoundRobin"].(bool)
conf := client.ConfigurationInfo{
Threads: threads,
SessionSemantic: sessionSemantic,
Time: time,
SwitchServer: switchServer,
Workload: workload,
PrimaryBackUpRoundRobin: primaryBackUpRoundRobin,
PrimaryBackupRandom: primaryBackupRandom,
GossipRandom: gossipRandom,
PinnedRoundRobin: pinnedRoundRobin,
}
fmt.Printf("%+v\n", conf)
client.Start(conf, servers)
case "server":
if len(os.Args) < 4 {
log.Fatalf("usage: go run main.go _ server [id] [gossip_interval]")
}
id, _ := strconv.ParseUint(os.Args[3], 10, 64)
gossipInterval, _ := strconv.ParseUint(os.Args[4], 10, 64)
// go func() {
server.Start(server.New(id, servers[id], servers, gossipInterval))
// }()
// time.Sleep(60 * time.Second)
// n := time.Now()
// for {
// if time.Since(n) > time.Duration(5*time.Second) {
// break
// }
// }
// pprof.StopCPUProfile()
// server.Start(server.New(id, servers[id], servers, gossipInterval))
default:
log.Fatalf("unknown command: %s", os.Args[1])
}
}