diff options
author | Yaroslav Brustinov <ybrustin@cisco.com> | 2016-12-10 22:23:31 +0200 |
---|---|---|
committer | Yaroslav Brustinov <ybrustin@cisco.com> | 2016-12-10 22:23:31 +0200 |
commit | 392ca5baf8c50c90e656981bde1571feaebc7a5a (patch) | |
tree | 9bfcfe2b66f8f67f8357f8eb2f94c165a9a6719f | |
parent | a4e6b32ed9b5b43f9a0e9ae78676c7f32866e4fc (diff) |
Stateless API: send batches by chunks
Change-Id: If551b474c4b6be58dfc3ed19e5c14a4ccd387afd
Signed-off-by: Yaroslav Brustinov <ybrustin@cisco.com>
-rw-r--r-- | scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_jsonrpc_client.py | 31 |
1 files changed, 27 insertions, 4 deletions
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 |