forked from adjust/go-wrk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
master_node.go
46 lines (43 loc) · 836 Bytes
/
master_node.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
package main
import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
"sync"
)
func MasterNode() {
distChannel := make(chan string, len(config.Nodes)*2)
wg := &sync.WaitGroup{}
for _, node := range config.Nodes {
go runChild(distChannel, wg, node)
wg.Add(1)
}
wg.Wait()
CalcDistStats(distChannel)
}
func runChild(distChan chan string, wg *sync.WaitGroup, node string) {
defer wg.Done()
toCall := fmt.Sprintf(
"http://%s/t=%d&m=%s&c=%d&n=%d&k=%t&url=%s",
node,
*numThreads,
*method,
*numConnections,
*totalCalls,
*disableKeepAlives,
url.QueryEscape(url.QueryEscape(target)),
)
fmt.Println(toCall)
resp, err := http.Get(toCall)
if err != nil {
fmt.Println(err)
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println(err)
}
distChan <- string(body)
}