Commit efd7f6f1 authored by Vincent Pelletier's avatar Vincent Pelletier

client.pool: Optimise getConnForNode for most likely execution path.

Connection is more often established than not, so do a first lookup without
locking, and only acquire it if it misses. Then do a second lookup in case
another thread also established connection, and connect if it still misses.
parent 8afbdd53
......@@ -143,10 +143,16 @@ class ConnectionPool(object):
If no connection exists, create a new one"""
if node.isRunning():
uuid = node.getUUID()
self.connection_lock_acquire()
try:
# Already connected to node
return self.connection_dict[uuid]
except KeyError:
self.connection_lock_acquire()
try:
# Second lookup, if another thread initiated connection
# while we were waiting for connection lock.
try:
return self.connection_dict[uuid]
except KeyError:
if len(self.connection_dict) > self.max_pool_size:
# must drop some unused connections
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment