d0995b37 by Lyu Kui

modify locustfile

1 parent a33165ce
...@@ -28,7 +28,7 @@ class F3Classification: ...@@ -28,7 +28,7 @@ class F3Classification:
28 28
29 res = { 29 res = {
30 'label': label, 30 'label': label,
31 'confidence': confidence 31 'confidence': float(confidence)
32 } 32 }
33 return res 33 return res
34 34
......
...@@ -14,3 +14,10 @@ class QuickstartUser(HttpUser): ...@@ -14,3 +14,10 @@ class QuickstartUser(HttpUser):
14 @task 14 @task
15 def async_test(self): 15 def async_test(self):
16 self.client.get("/async") 16 self.client.get("/async")
17
18 @tag('sync_classification')
19 @task
20 def sync_classification(self):
21 img_path = '/home/lk/MyProject/BMW_F3OCR/数据集/文件分类/营业执照/授信资料-43.jpg'
22 files=[('image', ('', open(img_path,'rb'), ''))]
23 self.client.post("/sync_classification", files=files)
......
1 import grpc 1 import os
2 import cv2 2 import cv2
3 import grpc
3 import numpy as np 4 import numpy as np
4 import tensorflow as tf 5 import tensorflow as tf
5 from tensorflow_serving.apis import prediction_service_pb2_grpc, predict_pb2 6 from tensorflow_serving.apis import prediction_service_pb2_grpc, predict_pb2
...@@ -8,6 +9,7 @@ from sanic import Sanic ...@@ -8,6 +9,7 @@ from sanic import Sanic
8 from sanic.response import json 9 from sanic.response import json
9 10
10 from classification import classifier 11 from classification import classifier
12 os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
11 13
12 app = Sanic("async_test") 14 app = Sanic("async_test")
13 15
...@@ -15,7 +17,7 @@ app = Sanic("async_test") ...@@ -15,7 +17,7 @@ app = Sanic("async_test")
15 tf_serving_settings = { 17 tf_serving_settings = {
16 'servers': { 18 'servers': {
17 'server_1': { 19 'server_1': {
18 'host': '192.168.10.191', 20 'host': 'localhost',
19 'port': '8500', 21 'port': '8500',
20 'options': [ 22 'options': [
21 ('grpc.max_send_message_length', 1000 * 1024 * 1024), 23 ('grpc.max_send_message_length', 1000 * 1024 * 1024),
...@@ -40,7 +42,7 @@ async def sync_handler(request): ...@@ -40,7 +42,7 @@ async def sync_handler(request):
40 request = predict_pb2.PredictRequest() 42 request = predict_pb2.PredictRequest()
41 request.model_spec.name = classifier.model_name 43 request.model_spec.name = classifier.model_name
42 request.model_spec.signature_name = classifier.signature_name 44 request.model_spec.signature_name = classifier.signature_name
43 stub = getattr(app.ctx, classifier.server_name) 45 stub = getattr(app, classifier.server_name)
44 46
45 request.inputs['input_1'].CopyFrom(tf.make_tensor_proto(input_images)) 47 request.inputs['input_1'].CopyFrom(tf.make_tensor_proto(input_images))
46 result = stub.Predict(request, 100.0) # 100 secs timeout 48 result = stub.Predict(request, 100.0) # 100 secs timeout
...@@ -63,7 +65,7 @@ async def set_grpc_channel(app, loop): ...@@ -63,7 +65,7 @@ async def set_grpc_channel(app, loop):
63 '{0}:{1}'.format(server_settings['host'], server_settings['port']), 65 '{0}:{1}'.format(server_settings['host'], server_settings['port']),
64 options=server_settings.get('options')) 66 options=server_settings.get('options'))
65 stub = prediction_service_pb2_grpc.PredictionServiceStub(channel) 67 stub = prediction_service_pb2_grpc.PredictionServiceStub(channel)
66 setattr(app.ctx, server_name, stub) 68 setattr(app, server_name, stub)
67 69
68 70
69 if __name__ == '__main__': 71 if __name__ == '__main__':
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!