From d4c210b97c4fd570eee78362999d0eff377726e5 Mon Sep 17 00:00:00 2001 From: Angel Luu Date: Thu, 9 Jun 2022 16:23:27 -0600 Subject: [PATCH 1/3] Add a GRPCClient that is re-usable by the same VU Signed-off-by: Angel Luu --- k6_test/grpc/script_grpc_skmnist.js | 32 +++++++++-------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/k6_test/grpc/script_grpc_skmnist.js b/k6_test/grpc/script_grpc_skmnist.js index ff05a12..b16a87e 100644 --- a/k6_test/grpc/script_grpc_skmnist.js +++ b/k6_test/grpc/script_grpc_skmnist.js @@ -1,37 +1,25 @@ -import grpc from 'k6/net/grpc'; -import { check } from 'k6'; -import execution from 'k6/execution'; +import { GrpcClient } from "../k6_test/grpc/grpc_client.js"; {{k6_opts}} -const client = new grpc.Client(); -client.load([], '../k6_test/kfs_inference_v2.proto'); +const sharedClient = new GrpcClient({ + grpcHost: '{{base_url}}', + protoFilePath: '../k6_test/kfs_inference_v2.proto', + inferRPCName: 'inference.GRPCInferenceService/ModelInfer' +}); const inputsData = JSON.parse(open(`../k6_test/payloads/{{payload}}`)); let params = { tags: { model_name: `{{model_name}}` }, } -export function setup(){ -// Abort on connection errors - try { - client.connect('{{base_url}}', { plaintext: true}); - } catch (error) { - check(error, {"Setup error": (error) => error === null}) - execution.test.abort(error); - } -} - export default () => { - client.connect('{{base_url}}', { plaintext: true }); const data = { "model_name": "{{model_name}}", "inputs": inputsData["inputs"] }; - const response = client.invoke('inference.GRPCInferenceService/ModelInfer', data, params); - - check(response, { - 'status is OK': (response) => response && response.status === grpc.StatusOK, - }); + sharedClient.infer(data, params); +}; - client.close(); +export function teardown() { + sharedClient.close(); }; From c66c02e9304b59dc282fff1239e3980371bbb65c Mon Sep 17 00:00:00 2001 From: Angel Luu Date: Thu, 9 Jun 2022 16:26:44 -0600 Subject: [PATCH 2/3] This file was not added in last commit Signed-off-by: Angel Luu --- k6_test/grpc/grpc_client.js | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 k6_test/grpc/grpc_client.js diff --git a/k6_test/grpc/grpc_client.js b/k6_test/grpc/grpc_client.js new file mode 100644 index 0000000..4634b58 --- /dev/null +++ b/k6_test/grpc/grpc_client.js @@ -0,0 +1,45 @@ +import { check } from "k6"; +import { Counter } from "k6/metrics"; +import grpc from "k6/net/grpc"; + +const grpcReqs = new Counter("grpc_reqs"); + +function getClient(protoFilePath) { + const client = new grpc.Client(); + + client.load([], protoFilePath); + + return client; +} + +function checkResponse(res) { + check(res, { + "status is OK": (r) => r && r.status === grpc.StatusOK, + }); +} + +export class GrpcClient { + constructor(options) { + this.grpcHost = options.grpcHost; + this.client = getClient(options.protoFilePath); + this.inferRPCName = options.inferRPCName; + + // Client can't connect on the init context + this.connected = false; + } + + infer(data, params) { + if (!this.connected) { + this.client.connect(this.grpcHost, { plaintext: true }); + this.connected = true; + } + + const res = this.client.invoke(this.inferRPCName, data, params); + checkResponse(res); + grpcReqs.add(1); + } + + close() { + this.client.close(); + } +} \ No newline at end of file From 42fd0026d156e0df77c23c7b22c15c0b8d9297c5 Mon Sep 17 00:00:00 2001 From: Angel Luu Date: Thu, 9 Jun 2022 16:35:54 -0600 Subject: [PATCH 3/3] Set some default options for grpc client Signed-off-by: Angel Luu --- k6_test/grpc/grpc_client.js | 6 +++--- k6_test/grpc/script_grpc_skmnist.js | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/k6_test/grpc/grpc_client.js b/k6_test/grpc/grpc_client.js index 4634b58..271d2d1 100644 --- a/k6_test/grpc/grpc_client.js +++ b/k6_test/grpc/grpc_client.js @@ -20,9 +20,9 @@ function checkResponse(res) { export class GrpcClient { constructor(options) { - this.grpcHost = options.grpcHost; - this.client = getClient(options.protoFilePath); - this.inferRPCName = options.inferRPCName; + this.grpcHost = options.grpcHost || 'modelmesh-serving:8033'; + this.client = getClient(options.protoFilePath || '../k6_test/kfs_inference_v2.proto'); + this.inferRPCName = options.inferRPCName || 'inference.GRPCInferenceService/ModelInfer'; // Client can't connect on the init context this.connected = false; diff --git a/k6_test/grpc/script_grpc_skmnist.js b/k6_test/grpc/script_grpc_skmnist.js index b16a87e..ded272d 100644 --- a/k6_test/grpc/script_grpc_skmnist.js +++ b/k6_test/grpc/script_grpc_skmnist.js @@ -3,9 +3,7 @@ import { GrpcClient } from "../k6_test/grpc/grpc_client.js"; {{k6_opts}} const sharedClient = new GrpcClient({ - grpcHost: '{{base_url}}', - protoFilePath: '../k6_test/kfs_inference_v2.proto', - inferRPCName: 'inference.GRPCInferenceService/ModelInfer' + grpcHost: '{{base_url}}' }); const inputsData = JSON.parse(open(`../k6_test/payloads/{{payload}}`)); let params = {