From 392ca5baf8c50c90e656981bde1571feaebc7a5a Mon Sep 17 00:00:00 2001 From: Yaroslav Brustinov Date: Sat, 10 Dec 2016 22:23:31 +0200 Subject: Stateless API: send batches by chunks Change-Id: If551b474c4b6be58dfc3ed19e5c14a4ccd387afd Signed-off-by: Yaroslav Brustinov --- .../stl/trex_stl_lib/trex_stl_jsonrpc_client.py | 31 +++++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'scripts/automation/trex_control_plane/stl/trex_stl_lib') diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_jsonrpc_client.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_jsonrpc_client.py index ce430e2b..fbad9f7f 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_jsonrpc_client.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_jsonrpc_client.py @@ -32,13 +32,36 @@ class BatchMessage(object): id, msg = self.rpc_client.create_jsonrpc_v2(method_name, params, api_class, encode = False) self.batch_list.append(msg) - def invoke(self, block = False): + def invoke(self, block = False, chunk_size = 500000): if not self.rpc_client.connected: return RC_ERR("Not connected to server") - msg = json.dumps(self.batch_list) - - return self.rpc_client.send_msg(msg) + if chunk_size: + response_batch = RC() + size = 0 + new_batch = [] + for msg in self.batch_list: + if size < chunk_size: + size += len(json.dumps(msg)) + new_batch.append(msg) + else: + batch_json = json.dumps(new_batch) + response = self.rpc_client.send_msg(batch_json) + if not response: + return response + response_batch.add(response) + size = 0 + new_batch = [] + if new_batch: + batch_json = json.dumps(new_batch) + response = self.rpc_client.send_msg(batch_json) + if not response: + return response + response_batch.add(response) + return response_batch + else: + batch_json = json.dumps(self.batch_list) + return self.rpc_client.send_msg(batch_json) # JSON RPC v2.0 client -- cgit 1.2.3-korg