This repository has been archived by the owner on May 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
52 lines (41 loc) · 1.48 KB
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from pairity.echo.v1 import echo_api_pb2 as echo_api, echo_api_pb2_grpc as echo_grpc
import grpc
import time
import multiprocessing as mp
from logzero import logger
REQUESTS = 10000
def _make_requests(worker_idx: int = 0):
try:
channel = grpc.insecure_channel('127.0.0.1:50051')
stub = echo_grpc.EchoAPIStub(channel)
request = echo_api.EchoRequest(something='anything')
start = time.time()
futures = []
logger.info('Worker %d: Making requests', worker_idx)
for _ in range(REQUESTS):
futures.append(stub.Echo.future(request))
logger.info('Worker %d: Requests made', worker_idx)
logger.info('Worker %d: Waiting for results', worker_idx)
for future in futures:
future.result()
logger.info('Received results - Returning...')
logger.info('Took %d to make %d requests', (time.time() - start), REQUESTS)
except KeyboardInterrupt:
logger.warning('Worker %d: Stopping...', worker_idx)
def main():
workers = []
for worker_idx in range(9):
worker = mp.Process(target=_make_requests, args=(worker_idx,))
worker.start()
workers.append(worker)
try:
for worker in workers:
worker.join()
workers.pop(0)
except KeyboardInterrupt:
logger.warning('Caught ctrl-c. Stopping workers...')
for worker in workers:
worker.kill()
worker.join()
if __name__ == '__main__':
main()