I also have a metric that surrounds the actual blocking call (I am using the blocking stub in this case).
Long time = System.currentTimeMillis();
Userprofile.ReadResponse resp = blockingStub
.withDeadlineAfter(timeout, TimeUnit.MILLISECONDS)
.get(req.build());
tick("GrpcClient.Get", System.currentTimeMillis() - time);
The issue is that this metric (the one surrounding the blocking call) is reporting a much lower latency (~100ms vs ~400ms). Why is there such a discrepancy? And which one is correct?
I will look into the ClientStreamTracer to see what's there as well. Thanks!
System.currentTimeMillis() is not ideal for measuring elapsed time. It's meant for measure the current time. Instead, try doing:
long startNanos = System.nanoTime();
// ... Do the RPC
long stopNanos = System.nanoTime();
tick("GrpcClient.Get", TimeUnit.NANOSECONDS.toMillis(stopNanos - startNanos));
As for the discrepancy, are you sure you don't have any exceptions being thrown? If the call failed the time would not be recorded. This is important for deadline exceeded calls, because they would make the average latency go way up.