Verified Commit 672e1dfb authored by Lohse, Felix's avatar Lohse, Felix
Browse files

added exercises

parent 0811ef63
Pipeline #40027 passed with stages
in 51 seconds
import requests, time, os
from statistics import median
import grpc
import helloworld_pb2
import helloworld_pb2_grpc
grpc_svc = os.environ.get("GRPC_SVC", "localhost")
grpc_port = os.environ.get("GRPC_PORT", "5555")
rest_svc = os.environ.get("REST_SVC", "localhost")
rest_port = os.environ.get("REST_PORT", "5000")
channel = grpc.insecure_channel(f"{ grpc_svc }:{ grpc_port }")
stub = helloworld_pb2_grpc.GreeterStub(channel)
grpc_s = []
rest_s = []
while True:
for i in range(0, 100):
start = time.time()
response = stub.SayHello(helloworld_pb2.HelloRequest(name='you'))
grpc_s.append(time.time() - start)
start = time.time()
x = requests.get(f"http://{ rest_svc }:{ rest_port }/hello/you")
rest_s.append(time.time() - start)
print(f"gRPC: { median(grpc_s) * 1000 :05.2f}ms REST: { median(rest_s) * 1000 :05.2f}ms")
import flask
app = flask.Flask(__name__)
@app.route('/', methods=['GET'])
def home():
return f"Hello!"
@app.route('/hello/<name>', methods=['GET'])
def hello(name):
return f"Hello, { name.strip() }!"
app.run(host="0.0.0.0")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment