You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add __slots__ to Host and HostConnection classes for memory optimization
This commit introduces __slots__ to the Host and HostConnection classes
in cassandra/pool.py to reduce memory footprint of frequently instantiated
objects in connection pools and cluster metadata.
Changes:
- Added __slots__ tuple to Host class with 18 actively used attributes
- Added __slots__ tuple to HostConnection class with 17 actively used attributes
- Consolidated class documentation from individual attribute docstrings
to comprehensive class-level docstrings
- Added explicit attribute initialization in __init__ methods to set
default values for attributes that previously relied on class variables
- Removed unused attributes (listen_address, listen_port) from Host class
after comprehensive usage analysis showed they were never used
- Fixed trailing whitespace issues in modified code
The __slots__ implementation prevents dynamic attribute creation and
reduces per-instance memory overhead, which is significant for drivers
managing large numbers of hosts and connections. All existing functionality
is preserved and tests continue to pass.
Memory impact: Each Host instance saves ~2 unused slots, and both classes
benefit from __slots__ memory layout optimization.
Signed-off-by: Yaniv Kaul <yaniv.kaul@scylladb.com>
@@ -49,123 +49,28 @@ class NoConnectionsAvailable(Exception):
49
49
classHost(object):
50
50
"""
51
51
Represents a single Cassandra node.
52
-
"""
53
-
54
-
endpoint=None
55
-
"""
56
-
The :class:`~.connection.EndPoint` to connect to the node.
57
-
"""
58
-
59
-
broadcast_address=None
60
-
"""
61
-
broadcast address configured for the node, *if available*:
62
-
63
-
'system.local.broadcast_address' or 'system.peers.peer' (Cassandra 2-3)
64
-
'system.local.broadcast_address' or 'system.peers_v2.peer' (Cassandra 4)
65
-
66
-
This is not present in the ``system.local`` table for older versions of Cassandra. It
67
-
is also not queried if :attr:`~.Cluster.token_metadata_enabled` is ``False``.
68
-
"""
69
-
70
-
broadcast_port=None
71
-
"""
72
-
broadcast port configured for the node, *if available*:
73
-
74
-
'system.local.broadcast_port' or 'system.peers_v2.peer_port' (Cassandra 4)
75
-
76
-
It is also not queried if :attr:`~.Cluster.token_metadata_enabled` is ``False``.
77
-
"""
78
-
79
-
broadcast_rpc_address=None
80
-
"""
81
-
The broadcast rpc address of the node:
82
-
83
-
'system.local.rpc_address' or 'system.peers.rpc_address' (Cassandra 3)
84
-
'system.local.rpc_address' or 'system.peers.native_transport_address (DSE 6+)'
85
-
'system.local.rpc_address' or 'system.peers_v2.native_address (Cassandra 4)'
86
-
"""
87
-
88
-
broadcast_rpc_port=None
89
-
"""
90
-
The broadcast rpc port of the node, *if available*:
91
-
92
-
'system.local.rpc_port' or 'system.peers.native_transport_port' (DSE 6+)
93
-
'system.local.rpc_port' or 'system.peers_v2.native_port' (Cassandra 4)
94
-
"""
95
-
96
-
listen_address=None
97
-
"""
98
-
listen address configured for the node, *if available*:
99
-
100
-
'system.local.listen_address'
101
-
102
-
This is only available in the ``system.local`` table for newer versions of Cassandra. It is also not
103
-
queried if :attr:`~.Cluster.token_metadata_enabled` is ``False``. Usually the same as ``broadcast_address``
104
-
unless configured differently in cassandra.yaml.
105
-
"""
106
-
107
-
listen_port=None
108
-
"""
109
-
listen port configured for the node, *if available*:
110
-
111
-
'system.local.listen_port'
112
-
113
-
This is only available in the ``system.local`` table for newer versions of Cassandra. It is also not
114
-
queried if :attr:`~.Cluster.token_metadata_enabled` is ``False``.
115
-
"""
116
-
117
-
conviction_policy=None
118
-
"""
119
-
A :class:`~.ConvictionPolicy` instance for determining when this node should
120
-
be marked up or down.
121
-
"""
122
-
123
-
is_up=None
124
-
"""
125
-
:const:`True` if the node is considered up, :const:`False` if it is
126
-
considered down, and :const:`None` if it is not known if the node is
127
-
up or down.
128
-
"""
129
-
130
-
release_version=None
131
-
"""
132
-
release_version as queried from the control connection system tables
133
-
"""
134
-
135
-
host_id=None
136
-
"""
137
-
The unique identifier of the cassandra node
138
-
"""
139
-
140
-
dse_version=None
141
-
"""
142
-
dse_version as queried from the control connection system tables. Only populated when connecting to
143
-
DSE with this property available. Not queried if :attr:`~.Cluster.token_metadata_enabled` is ``False``.
144
-
"""
145
-
146
-
dse_workload=None
147
-
"""
148
-
DSE workload queried from the control connection system tables. Only populated when connecting to
149
-
DSE with this property available. Not queried if :attr:`~.Cluster.token_metadata_enabled` is ``False``.
150
-
This is a legacy attribute that does not portray multiple workloads in a uniform fashion.
151
-
See also :attr:`~.Host.dse_workloads`.
152
-
"""
153
-
154
-
dse_workloads=None
155
-
"""
156
-
DSE workloads set, queried from the control connection system tables. Only populated when connecting to
157
-
DSE with this property available (added in DSE 5.1).
158
-
Not queried if :attr:`~.Cluster.token_metadata_enabled` is ``False``.
159
-
"""
160
-
161
-
_datacenter=None
162
-
_rack=None
163
-
_reconnection_handler=None
164
-
lock=None
165
52
166
-
_currently_handling_node_up=False
167
-
168
-
sharding_info=None
53
+
Attributes:
54
+
endpoint: The :class:`~.connection.EndPoint` to connect to the node.
55
+
broadcast_address: broadcast address configured for the node, *if available*
56
+
broadcast_port: broadcast port configured for the node, *if available*
57
+
broadcast_rpc_address: The broadcast rpc address of the node
58
+
broadcast_rpc_port: The broadcast rpc port of the node, *if available*
59
+
conviction_policy: A :class:`~.ConvictionPolicy` instance for determining when this node should be marked up or down.
60
+
is_up: :const:`True` if the node is considered up, :const:`False` if it is considered down, and :const:`None` if it is not known if the node is up or down.
61
+
release_version: release_version as queried from the control connection system tables
62
+
host_id: The unique identifier of the cassandra node
63
+
dse_version: dse_version as queried from the control connection system tables
64
+
dse_workload: DSE workload queried from the control connection system tables
65
+
dse_workloads: DSE workloads set, queried from the control connection system tables
# this is used in conjunction with the connection streams. Not using the connection lock because the connection can be replaced in the lifetime of the pool.
0 commit comments