grpc python measure response time

Viewed 860

How can I measure the full time grpc-python takes to handle a request? So far the best I can do is:

def Run(self, request, context):
   start = time.time()
   # service code...
   end = time.time()
   return myservice_stub.Response()

But this doesn't measure how much time grpc takes to serialize the request, response, to transfer it over the network.. and so on. I'm looking for a way to "hook" into these steps.

1 Answers

You can measure on the client side:

start = time.time()
response = stub.Run(request)
total_end_to_end = time.time() - start

Then you can get the total overhead (serialization, transfer) by reducing the computation of the Run method.

To automate the process, you can add (at least for the sake of the test) the computation time as a field to the myservice_stub.Response.

Related