Use a network cache in Instance
When listing NICs for an instance populate a class global cache of networks by network_id. When listing nodes with VIFs on the same network this reduces the amount of calls to the network service. 250 Nodes without patch: real 6m29.342s 250 Nodes with patch: real 5m26.544s Story: 2010571 Task: 47301 Change-Id: I99a2d8ecab657c8e4c852c73e816a5a8f2856471
This commit is contained in:
parent
a5fffb9242
commit
9c2252ea88
@ -73,6 +73,8 @@ _DEPLOYED_STATES = frozenset([InstanceState.ACTIVE, InstanceState.MAINTENANCE])
|
|||||||
class Instance(object):
|
class Instance(object):
|
||||||
"""Instance status in metalsmith."""
|
"""Instance status in metalsmith."""
|
||||||
|
|
||||||
|
network_cache = dict()
|
||||||
|
|
||||||
def __init__(self, connection, node, allocation=None):
|
def __init__(self, connection, node, allocation=None):
|
||||||
self._connection = connection
|
self._connection = connection
|
||||||
self._uuid = node.id
|
self._uuid = node.id
|
||||||
@ -124,8 +126,10 @@ class Instance(object):
|
|||||||
for vif in vifs:
|
for vif in vifs:
|
||||||
try:
|
try:
|
||||||
port = self._connection.network.get_port(vif)
|
port = self._connection.network.get_port(vif)
|
||||||
port.network = self._connection.network.get_network(
|
if port.network_id not in Instance.network_cache:
|
||||||
port.network_id)
|
Instance.network_cache[port.network_id] = (
|
||||||
|
self._connection.network.get_network(port.network_id))
|
||||||
|
port.network = Instance.network_cache[port.network_id]
|
||||||
result.append(port)
|
result.append(port)
|
||||||
except os_exc.ResourceNotFound:
|
except os_exc.ResourceNotFound:
|
||||||
LOG.warning('vif has missing port: %s', vif)
|
LOG.warning('vif has missing port: %s', vif)
|
||||||
|
Loading…
Reference in New Issue
Block a user