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

Function getRatio

pbbenchmark/main.go:49–91  ·  view source on GitHub ↗
(q string, hc *http.Client, c graph.DGraphClient)

Source from the content-addressed store, hash-verified

47}
48
49func getRatio(q string, hc *http.Client, c graph.DGraphClient) (numEntities int,
50 ratio float64, jsonLatency int64) {
51 var dat map[string]interface{}
52 var latency map[string]interface{}
53
54 r, err := http.NewRequest("POST", *serverAddr, bytes.NewBufferString(q))
55 checkErr(err, "Error while forming request")
56
57 resp, err := hc.Do(r)
58 checkErr(err, "Error in query")
59 if err != nil {
60 glog.WithField("Err", err).Fatalf("Error in query")
61 } else {
62
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 if err = json.Unmarshal(body, &dat); err != nil {
69 glog.Fatalf("Error in reply")
70 }
71 numEntities = strings.Count(string(body), "_uid_")
72 }
73 temp := dat["server_latency"]
74 latency = temp.(map[string]interface{})
75
76 jsonTime, _ := time.ParseDuration(latency["json"].(string))
77
78 res, err := c.Query(context.Background(), &graph.Request{Query: q})
79 if err != nil {
80 log.Fatal("Error in getting response from server")
81 }
82
83 if numEntities != numChildren(res.N) {
84 log.Fatal("Number of entities in json and protocol buffer differ")
85 }
86 pbTime, _ := time.ParseDuration(res.L.Pb)
87 ratio = float64(pbTime.Nanoseconds()) / float64(jsonTime.Nanoseconds())
88 // Latency in milliseconds
89 jsonLatency = jsonTime.Nanoseconds()/10 ^ 6
90 return
91}
92
93type eRatio struct {
94 // Count of results that have the same number of entities.

Callers 1

QueryFunction · 0.85

Calls 4

checkErrFunction · 0.85
numChildrenFunction · 0.85
CloseMethod · 0.65
UnmarshalMethod · 0.45

Tested by

no test coverage detected