Skip to content

Commit 9c53d78

Browse files
mykaulLorak-mmk
authored andcommitted
(improvement) cluster: cache parsed tablet routing type in ResponseFuture
The _set_result() method re-parses the same complex TupleType string on every query result that includes tablet routing info. Cache the parsed type as a class attribute on ResponseFuture so lookup_casstype() is only called once for the lifetime of the process.
1 parent 1ec7f66 commit 9c53d78

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

cassandra/cluster.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4345,6 +4345,7 @@ class ResponseFuture(object):
43454345
_spec_execution_plan = NoSpeculativeExecutionPlan()
43464346
_continuous_paging_session = None
43474347
_host = None
4348+
_TABLET_ROUTING_CTYPE = None
43484349

43494350
_warned_timeout = False
43504351

@@ -4642,7 +4643,10 @@ def _set_result(self, host, connection, pool, response):
46424643
if self._custom_payload and self.session.cluster.control_connection._tablets_routing_v1 and 'tablets-routing-v1' in self._custom_payload:
46434644
protocol = self.session.cluster.protocol_version
46444645
info = self._custom_payload.get('tablets-routing-v1')
4645-
ctype = types.lookup_casstype('TupleType(LongType, LongType, ListType(TupleType(UUIDType, Int32Type)))')
4646+
ctype = ResponseFuture._TABLET_ROUTING_CTYPE
4647+
if ctype is None:
4648+
ctype = types.lookup_casstype('TupleType(LongType, LongType, ListType(TupleType(UUIDType, Int32Type)))')
4649+
ResponseFuture._TABLET_ROUTING_CTYPE = ctype
46464650
tablet_routing_info = ctype.from_binary(info, protocol)
46474651
first_token = tablet_routing_info[0]
46484652
last_token = tablet_routing_info[1]

0 commit comments

Comments
 (0)