Skip to content

Commit

Permalink
Merge pull request tobegit3hub#22 from yejw5/wait_callback
Browse files Browse the repository at this point in the history
wait callback
  • Loading branch information
tobegit3hub authored Apr 6, 2017
2 parents 0c0854c + b2daa9a commit 29003e5
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions minimal_model/python_predict_client/benchmark_qps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import numpy
import multiprocessing
import threading
import time

from grpc.beta import implementations
Expand All @@ -21,8 +22,9 @@
FLAGS = tf.app.flags.FLAGS


def _create_rpc_callback():
def _create_rpc_callback(event):
def _callback(result_future):
event.set()
exception = result_future.exception()
if exception:
print(exception)
Expand Down Expand Up @@ -59,16 +61,22 @@ def test_one_process(i):
request_number = FLAGS.benchmark_test_number
#start_time = time.time()

events = []
for i in range(request_number):
event = threading.Event()
result_future = stub.Predict.future(request, request_timeout)
#result_future = stub.Predict.future(request, 0.00000001)
result_future.add_done_callback(_create_rpc_callback())
result_future.add_done_callback(_create_rpc_callback(event))
events.append(event)
#result = stub.Predict(request, request_timeout)

#end_time = time.time()
#print("Average latency is: {} ms".format((end_time - start_time) * 1000 / request_number))
#print("Average qps is: {}".format(request_number / (end_time - start_time)))

for event in events:
event.wait()


def main():
thread_number = FLAGS.benchmark_thread_number
Expand Down

0 comments on commit 29003e5

Please sign in to comment.