Is there any easy way to print server time and round-trip time after execution Query complete in Javascipt? I have seen this in webadmin, but could not found in API. For the Benchmarking purpose of Query, which one should we consider?
Asked
Active
Viewed 248 times
2 Answers
2
To add to Jorge's answer about measuring round-trip time: You can obtain the server time from the query profile. This is also what the Data Explorer (web UI) uses.
Profiling must be enabled by passing the {profile: true}
optarg into run
.
As a result, you get an object with the profile in a profile
field, and the query result in a value
field of the result.
For example in JavaScript:
r.expr("test query").run(conn, {profile: true}, function(err, result) {
var serverTime = result.profile[0]['duration(ms)'];
console.log(serverTime);
});

Daniel Mewes
- 1,876
- 14
- 16
-
Regarding which one to use for benchmarking: It depends on what exactly you want to measure. If your client hardware and configuration is identical to what you'll use in your actual production setup, measuring round-trip time gives you a more realistic timing that includes overhead for the transferring the result over the network and for decoding it on the client. If on the other hand you want to measure server performance only (e.g. your client setup isn't final yet), server time might be more useful. – Daniel Mewes Apr 07 '15 at 18:58
1
For round-trip time you can just use the console, by using the .time
and .timeEnd
methods.
Example:
console.time('query');
r.table('table_name')
.filter({ name: 'jorge' })
.run(conn)
.then(function (cursor) {
console.timeEnd('query');
});
You can find the documentation for these methods in MDN:
https://developer.mozilla.org/en-US/docs/Web/API/Console/time
https://developer.mozilla.org/en-US/docs/Web/API/Console/timeEnd

Jorge Silva
- 4,574
- 1
- 23
- 42