MCPcopy Create free account
hub / github.com/dgraph-io/dgraph-benchmarks / runUser

Function runUser

throughputtest/throughPut.go:103–178  ·  view source on GitHub ↗
(wg *sync.WaitGroup)

Source from the content-addressed store, hash-verified

101}`
102
103func runUser(wg *sync.WaitGroup) {
104 var proT, parT, jsonT, totT time.Duration
105 var count int
106
107 client := &http.Client{Transport: &http.Transport{
108 MaxIdleConnsPerHost: 100,
109 }}
110 var dat map[string]interface{}
111 var latency map[string]interface{}
112 var extensions map[string]interface{}
113
114 tix := time.Now()
115
116 for time.Now().Sub(tix).Seconds() < *numSec {
117 var choose = rand.Intn(2)
118 var query string
119 if choose == 1 {
120 var ridx = rand.Intn(len(actors))
121 query = qa1 + actors[ridx] + qa2
122 } else {
123 var ridx = rand.Intn(len(directors))
124 query = qd1 + directors[ridx] + qd2
125 }
126
127 r, _ := http.NewRequest("POST", serverList[rand.Intn(len(serverList))], bytes.NewBufferString(query))
128 resp, err := client.Do(r)
129
130 count++
131
132 if err != nil {
133 log.Fatal(err)
134 } else {
135 body, err := ioutil.ReadAll(resp.Body)
136 if err != nil {
137 log.Fatalf("Couldn't parse response body. %+v", err)
138 }
139 resp.Body.Close()
140 err = json.Unmarshal(body, &dat)
141 if err != nil {
142 log.Fatal(err)
143 }
144
145 var ok bool
146
147 temp := dat["extensions"]
148 extensions, ok = temp.(map[string]interface{})
149 if !ok {
150 log.Print("no 'extensions' in response data")
151 log.Fatalf("%#v", dat)
152 }
153
154 temp = extensions["server_latency"]
155 latency, ok = temp.(map[string]interface{})
156 if !ok {
157 log.Print("no 'server_latency' in extension data'")
158 log.Fatalf("%#v", extensions)
159 }
160

Callers 1

mainFunction · 0.70

Calls 3

DoneMethod · 0.80
CloseMethod · 0.65
UnmarshalMethod · 0.45

Tested by

no test coverage detected