-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpeerobjects.go
More file actions
63 lines (53 loc) · 1.59 KB
/
peerobjects.go
File metadata and controls
63 lines (53 loc) · 1.59 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
package main
import (
"flag"
"fmt"
"os"
"runtime"
"time"
"github.com/jefferickson/peer-object-matcher/object"
)
// config vars
var inputFile string
var lagFile string
var outputFile string
var maxPeers int
var maxBlockSize int
var cpuLimit int
func init() {
// parse command line args
flag.StringVar(&inputFile, "input", "", "The input CSV. [REQUIRED]")
flag.StringVar(&lagFile, "lag", "", "The input CSV for lag peers.")
flag.StringVar(&outputFile, "output", "", "The output CSV. [REQUIRED]")
flag.IntVar(&maxPeers, "maxpeers", 50, "The maximum number of peers.")
flag.IntVar(&maxBlockSize, "maxblocksize", 5000, "The maximum number of objects per routine.")
flag.IntVar(&cpuLimit, "cpulimit", 0, "The max number of CPU cores to utilize.")
flag.Parse()
// ensure we have the minimum reqs
if inputFile == "" || outputFile == "" {
flag.Usage()
os.Exit(2)
}
}
func main() {
// keep track of time
start := time.Now()
// set max number of CPUs
runtime.GOMAXPROCS(cpuLimit)
// process the input file and start up! if there is a lag file, process that too
// otherwise set those in the input file to be their own peers
objects, total_n := object.ProcessInputCSV(inputFile)
var peers map[string][]*object.Object
if lagFile != "" {
peers, _ = object.ProcessInputCSV(lagFile)
} else {
// the objects will be the peers themselves
peers = objects
}
allObjects := object.ObjectsToPeer{Objects: objects, Peers: peers, N: total_n}
allObjects.Run(maxPeers, outputFile, maxBlockSize)
// How long did it take?
elapsed := time.Since(start)
fmt.Printf("\n")
fmt.Println("Completed in", elapsed)
}