diff --git a/nebula2/data/ResultSet.py b/nebula2/data/ResultSet.py index 64e735c9..bc4e90de 100644 --- a/nebula2/data/ResultSet.py +++ b/nebula2/data/ResultSet.py @@ -12,13 +12,14 @@ class ResultSet(object): - def __init__(self, resp, decode_type='utf-8'): + def __init__(self, resp, _all_latency, decode_type='utf-8'): """ get data from ResultSet """ self._decode_type = decode_type self._resp = resp self._data_set_wrapper = None + self._all_latency = _all_latency; if self._resp.data is not None: self._data_set_wrapper = DataSetWrapper(resp.data, self._decode_type) @@ -45,10 +46,16 @@ def comment(self): def latency(self): """ - unit us + the server's latency, unit us """ return self._resp.latency_in_us + def whole_latency(self): + """ + the whole latency of the query + """ + return self._all_latency + def plan_desc(self): return self._resp.plan_desc diff --git a/nebula2/gclient/net/__init__.py b/nebula2/gclient/net/__init__.py index 40df4754..2cb06ebe 100644 --- a/nebula2/gclient/net/__init__.py +++ b/nebula2/gclient/net/__init__.py @@ -54,7 +54,10 @@ def execute(self, stmt): if self._connection is None: raise RuntimeError('The session has released') try: - return ResultSet(self._connection.execute(self.session_id, stmt)) + start_time = time.time() + resp = self._connection.execute(self.session_id, stmt) + end_time = time.time() + return ResultSet(resp, int((end_time - start_time) * 1000000)) except IOErrorException as ie: if ie.type == IOErrorException.E_CONNECT_BROKEN: self._pool.update_servers_status() @@ -63,7 +66,9 @@ def execute(self, stmt): logging.warning('Retry connect failed') raise IOErrorException(IOErrorException.E_ALL_BROKEN, 'All connections are broken') try: - return ResultSet(self._connection.execute(self.session_id, stmt)) + self._connection.execute(self.session_id, stmt) + end_time = time.time() + return ResultSet(resp, int((end_time - start_time) * 1000000)) except Exception: raise raise diff --git a/tests/test_data_from_server.py b/tests/test_data_from_server.py index 92ef8e2e..67b12bb8 100644 --- a/tests/test_data_from_server.py +++ b/tests/test_data_from_server.py @@ -229,3 +229,7 @@ def test_path_type(self): 'start_school: 2017-09-10, child_name: "Hello Worl", morning: 07:10:00.000000, ' \ 'friends: 10, first_out_city: 1111, name: "Lily"})' assert expected_str == str(path) + + assert resp.whole_latency() > 100 + +