Skip to content
This repository was archived by the owner on Sep 5, 2025. It is now read-only.

Conversation

@danielmai
Copy link
Contributor

@danielmai danielmai commented May 12, 2021

This is for CLOUD-260.

This adds an example to get the client-side and the server-side latency of a query.

The important bit is the following snippet:

console.time('Query client latency');
const res = await dgraphClient.newTxn().queryWithVars(query, vars);
console.timeEnd('Query client latency');
console.log("Query server latency:", JSON.stringify(res.extensions.server_latency));

Client-side latency is calculated using console.time and console.timeEnd around a query call to capture the client-side latency.

Server-side latency is calculated by Dgraph itself. This example prints it out from the query response res.extensions.server_latency.


Example command and output:

$ node index-async-await.js --addr https://$MY_DGRAPH_CLOUD_ENDPOINT --api-key $MY_API_KEY --drop-all
Created person named "Alice" with uid = 0xbd

All created nodes (map from blank node names to uids):
blank-0 => 0xbd
dg.3043386991.125 => 0xbe
dg.3043386991.126 => 0xbf
dg.3043386991.127 => 0xc0

Query: query all($a: string) { all(func: eq(name, $a)) { uid name age married loc dob friend { name age } school { name } } } Vars: { '$a': 'Alice' }
Query client latency: 39.371ms
Query server latency: {"parsing_ns":299313,"processing_ns":1606551,"encoding_ns":361067,"assign_timestamp_ns":1389885,"total_ns":3770262}
Number of people named "Alice": 1
{
  uid: '0xbd',
  name: 'Alice',
  age: 26,
  married: true,
  loc: { type: 'Point', coordinates: [ 1.1, 2 ] },
  dob: '1980-02-02T07:00:00Z',
  friend: [ { name: 'Bob', age: 24 }, { name: 'Charlie', age: 29 } ],
  school: [ { name: 'Crown Public School' } ]
}

DONE!

The following flags are available in this example:

This change is Reviewable

@danielmai danielmai merged commit f54ba7b into master Jun 16, 2021
@danielmai danielmai deleted the danielmai/example-latency branch June 16, 2021 20:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants