Skip to content

Commit

Permalink
add whole_latency
Browse files Browse the repository at this point in the history
  • Loading branch information
laura-ding committed Apr 1, 2021
1 parent c913f01 commit 11dc71a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
11 changes: 9 additions & 2 deletions nebula2/data/ResultSet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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

Expand Down
9 changes: 7 additions & 2 deletions nebula2/gclient/net/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/test_data_from_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


0 comments on commit 11dc71a

Please sign in to comment.