| 33 | ) |
| 34 | |
| 35 | func runUser(wg *sync.WaitGroup) { |
| 36 | var ti, proT, parT, jsonT, totT time.Duration |
| 37 | var query = `{ |
| 38 | me(_xid_: m.0f4vbz) { |
| 39 | type.object.name.en |
| 40 | film.actor.film { |
| 41 | film.performance.film { |
| 42 | type.object.name.en |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | }` |
| 47 | |
| 48 | client := &http.Client{Transport: &http.Transport{ |
| 49 | MaxIdleConnsPerHost: 100, |
| 50 | }} |
| 51 | var dat map[string]interface{} |
| 52 | var latency map[string]interface{} |
| 53 | for i := 0; i < *numReq; i++ { |
| 54 | r, _ := http.NewRequest("POST", *serverAddr, bytes.NewBufferString(query)) |
| 55 | |
| 56 | t0 := time.Now() |
| 57 | //fmt.Println(i) |
| 58 | resp, err := client.Do(r) |
| 59 | t1 := time.Now() |
| 60 | if err != nil { |
| 61 | glog.WithField("Err", resp.Status).Fatalf("Error in query") |
| 62 | } else { |
| 63 | body, err := ioutil.ReadAll(resp.Body) |
| 64 | if err != nil { |
| 65 | log.Fatalf("Couldn't parse response body. %+v", err) |
| 66 | } |
| 67 | resp.Body.Close() |
| 68 | err = json.Unmarshal(body, &dat) |
| 69 | if err != nil { |
| 70 | glog.Fatalf("Error in reply") |
| 71 | } |
| 72 | //fmt.Println(dat["server_latency"]) |
| 73 | ti += t1.Sub(t0) |
| 74 | // json:1.144568ms parsing:4.031346ms processing:3.726298ms total:8.904975ms |
| 75 | temp := dat["server_latency"] |
| 76 | latency = temp.(map[string]interface{}) |
| 77 | |
| 78 | pro, _ := time.ParseDuration(latency["processing"].(string)) |
| 79 | proT += pro |
| 80 | js, _ := time.ParseDuration(latency["json"].(string)) |
| 81 | jsonT += js |
| 82 | par, _ := time.ParseDuration(latency["parsing"].(string)) |
| 83 | parT += par |
| 84 | tot, _ := time.ParseDuration(latency["total"].(string)) |
| 85 | totT += tot |
| 86 | } |
| 87 | // fmt.Println("user", i) |
| 88 | } |
| 89 | avg <- ti.Seconds() |
| 90 | serverP <- proT.Seconds() |
| 91 | jsonP <- jsonT.Seconds() |
| 92 | parsingP <- parT.Seconds() |