-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
92 lines (77 loc) · 1.81 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"flag"
"fmt"
"io"
"log"
"os"
"time"
)
func databaseTemp(path string) (*os.File, error) {
_, err := os.Stat(path)
if err != nil {
return nil, err
}
tempDB, err := os.CreateTemp("", "status-go-db-perf-temp")
if err != nil {
return nil, err
}
sourceDB, err := os.Open(path)
if err != nil {
return nil, err
}
if _, err = io.Copy(tempDB, sourceDB); err != nil {
return nil, err
}
sourceDB.Close()
tempDB.Close()
return tempDB, nil
}
func profile(dbPath string, key string, maxOpenConns int, maxIdleConns int) (time.Duration, error) {
tempDB, err := databaseTemp(dbPath)
if err != nil {
return 0, err
}
defer os.Remove(tempDB.Name())
log.Println("Temporary database created: ", tempDB.Name())
persistence, err := NewPersistence(tempDB.Name(), key, maxOpenConns, maxIdleConns)
if err != nil {
return 0, err
}
defer persistence.Cleanup()
profiler, err := NewPersistenceProfiler(persistence)
if err != nil {
return 0, err
}
defer profiler.Cleanup()
start := time.Now()
if err := profiler.Perform(); err != nil {
return 0, err
}
return time.Since(start), nil
}
func main() {
dbPath := flag.String("dbPath", "", "Path to the database")
key := flag.String("key", "", `"0x" + lowercase(keccak256(clearPassword))`)
flag.Parse()
csvFile, err := os.Create("output/perf-compare-connections-config" + fmt.Sprint(time.Now().Unix()) + ".csv")
if err != nil {
log.Println(err)
return
}
defer csvFile.Close()
for i := 1; i <= 20; i++ {
for j := 1; j <= i; j++ {
result, err := profile(*dbPath, *key, i, j)
if err != nil {
log.Println(err)
return
}
line := fmt.Sprintf("%d %d %d\n", i, j, result.Milliseconds())
if _, err := csvFile.Write([]byte(line)); err != nil {
log.Println("could not write to csv", err)
}
log.Print(line)
}
}
}