Skip to content

Commit

Permalink
Add total time taken to process a query in result
Browse files Browse the repository at this point in the history
  • Loading branch information
mangalaman93 committed Nov 22, 2019
1 parent 8c97188 commit ba21945
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 11 deletions.
10 changes: 2 additions & 8 deletions dgraph/cmd/counter/increment.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ func queryCounter(ctx context.Context, txn *dgo.Txn, pred string) (Counter, erro
return counter, errors.Wrapf(err, "while doing query")
}

// Total query latency is sum of encoding, parsing and processing latencies.
queryLatency := resp.Latency.GetEncodingNs() +
resp.Latency.GetParsingNs() + resp.Latency.GetProcessingNs()

m := make(map[string][]Counter)
if err := json.Unmarshal(resp.Json, &m); err != nil {
return counter, err
Expand All @@ -105,7 +101,7 @@ func queryCounter(ctx context.Context, txn *dgo.Txn, pred string) (Counter, erro
}
span.Annotatef(nil, "Found counter: %+v", counter)
counter.startTs = resp.GetTxn().GetStartTs()
counter.qLatency = time.Duration(queryLatency).Round(time.Millisecond)
counter.qLatency = time.Duration(resp.Latency.GetTotalNs()).Round(time.Millisecond)
return counter, nil
}

Expand Down Expand Up @@ -154,9 +150,7 @@ func process(dg *dgo.Dgraph, conf *viper.Viper) (Counter, error) {
return Counter{}, err
}

mutationLatency := resp.Latency.GetProcessingNs() +
resp.Latency.GetParsingNs() + resp.Latency.GetEncodingNs()
counter.mLatency = time.Duration(mutationLatency).Round(time.Millisecond)
counter.mLatency = time.Duration(resp.Latency.GetTotalNs()).Round(time.Millisecond)
return counter, nil
}

Expand Down
1 change: 1 addition & 0 deletions edgraph/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,7 @@ func (s *Server) doQuery(ctx context.Context, req *api.Request, authorize int) (
ParsingNs: uint64(l.Parsing.Nanoseconds()),
ProcessingNs: uint64(l.Processing.Nanoseconds()),
EncodingNs: uint64(l.Json.Nanoseconds()),
TotalNs: uint64((time.Since(l.Start)).Nanoseconds()),
}

return resp, nil
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/blevesearch/snowballstem v0.0.0-20180110192139-26b06a2c243d // indirect
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd
github.com/dgraph-io/badger/v2 v2.0.0
github.com/dgraph-io/dgo/v2 v2.1.1-0.20191121195227-2007f080576e
github.com/dgraph-io/dgo/v2 v2.1.1-0.20191122140656-1f7da0542457
github.com/dgraph-io/ristretto v0.0.0-20191114170855-99d1bbbf28e6 // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/dgryski/go-farm v0.0.0-20191112170834-c2139c5d712b
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgraph-io/badger/v2 v2.0.0 h1:Cr05o2TUd2IcLbEY0aGd8mbjm1YyQpy+dswo3BcDXrE=
github.com/dgraph-io/badger/v2 v2.0.0/go.mod h1:YoRSIp1LmAJ7zH7tZwRvjNMUYLxB4wl3ebYkaIruZ04=
github.com/dgraph-io/dgo/v2 v2.1.1-0.20191121195227-2007f080576e h1:rKTDpjd4/aeilP50r26p5RKESz/vrSXzrf4Boy0baLM=
github.com/dgraph-io/dgo/v2 v2.1.1-0.20191121195227-2007f080576e/go.mod h1:LJCkLxm5fUMcU+yb8gHFjHt7ChgNuz3YnQQ6MQkmscI=
github.com/dgraph-io/dgo/v2 v2.1.1-0.20191122140656-1f7da0542457 h1:evAEDyRyAmfcNN6mFheIMfvLnpCb6FvctfStQhyqZzk=
github.com/dgraph-io/dgo/v2 v2.1.1-0.20191122140656-1f7da0542457/go.mod h1:LJCkLxm5fUMcU+yb8gHFjHt7ChgNuz3YnQQ6MQkmscI=
github.com/dgraph-io/ristretto v0.0.0-20191025175511-c1f00be0418e h1:aeUNgwup7PnDOBAD1BOKAqzb/W/NksOj6r3dwKKuqfg=
github.com/dgraph-io/ristretto v0.0.0-20191025175511-c1f00be0418e/go.mod h1:edzKIzGvqUCMzhTVWbiTSe75zD9Xxq0GtSBtFmaUTZs=
github.com/dgraph-io/ristretto v0.0.0-20191114170855-99d1bbbf28e6 h1:liDEMz8LbPxfuI8e/noprwccn6gZGv2rN1AgucbxjHs=
Expand Down

0 comments on commit ba21945

Please sign in to comment.