performance improvement in the processor.

Use set instead of using list.

Change-Id: I61fd045b8e228d06aeb3221dc753079a123ec11c
This commit is contained in:
Alexey 2017-05-17 11:29:18 +00:00
parent 09c4b8df98
commit 0e93ae638e
7 changed files with 19 additions and 23 deletions

View File

@ -36,7 +36,7 @@ OPTS = [
' datasource itself.', ' datasource itself.',
required=True), required=True),
cfg.IntOpt(DSOpts.CHANGES_INTERVAL, cfg.IntOpt(DSOpts.CHANGES_INTERVAL,
default=20, default=10,
min=20, min=10,
help='interval between checking changes in aodh data source'), help='interval between checking changes in aodh data source'),
] ]

View File

@ -36,8 +36,8 @@ OPTS = [
' datasource itself.', ' datasource itself.',
required=True), required=True),
cfg.IntOpt(DSOpts.CHANGES_INTERVAL, cfg.IntOpt(DSOpts.CHANGES_INTERVAL,
default=30, default=20,
min=30, min=10,
help='interval between checking changes in nagios data source'), help='interval between checking changes in nagios data source'),
cfg.StrOpt('user', default='nagiosadmin', cfg.StrOpt('user', default='nagiosadmin',
help='Nagios user name'), help='Nagios user name'),

View File

@ -120,5 +120,5 @@ class ChangesService(DatasourceService):
for entity in datasource.get_changes(DatasourceAction.UPDATE): for entity in datasource.get_changes(DatasourceAction.UPDATE):
self.send_to_queue(entity) self.send_to_queue(entity)
except Exception as e: except Exception as e:
LOG.error("Get changes Failed - %s", str(e)) LOG.exception("Get changes Failed - %s", e)
LOG.debug("end get changes") LOG.debug("end get changes")

View File

@ -38,6 +38,7 @@ OPTS = [
required=True), required=True),
cfg.IntOpt(DSOpts.CHANGES_INTERVAL, cfg.IntOpt(DSOpts.CHANGES_INTERVAL,
default=30, default=30,
min=10,
help='interval in seconds between checking changes in the' help='interval in seconds between checking changes in the'
'static configuration files'), 'static configuration files'),
# NOTE: This folder is already used by static_physical datasource. Legacy # NOTE: This folder is already used by static_physical datasource. Legacy

View File

@ -36,7 +36,7 @@ OPTS = [
' datasource itself.', ' datasource itself.',
required=True), required=True),
cfg.IntOpt(DSOpts.CHANGES_INTERVAL, cfg.IntOpt(DSOpts.CHANGES_INTERVAL,
default=30, default=20,
min=10, min=10,
help='interval between checking changes in zabbix data source'), help='interval between checking changes in zabbix data source'),
cfg.StrOpt('user', default='admin', cfg.StrOpt('user', default='admin',

View File

@ -84,7 +84,7 @@ class Processor(processor.ProcessorBase):
# so it will be done in one central place # so it will be done in one central place
self._find_and_fix_graph_vertex(new_vertex, neighbors) self._find_and_fix_graph_vertex(new_vertex, neighbors)
self.entity_graph.add_vertex(new_vertex) self.entity_graph.add_vertex(new_vertex)
self._connect_neighbors(neighbors, [], GraphAction.CREATE_ENTITY) self._connect_neighbors(neighbors, set(), GraphAction.CREATE_ENTITY)
def update_entity(self, updated_vertex, neighbors): def update_entity(self, updated_vertex, neighbors):
"""Updates the vertex in the entity graph """Updates the vertex in the entity graph
@ -235,8 +235,8 @@ class Processor(processor.ProcessorBase):
2. connects the new neighbors. 2. connects the new neighbors.
""" """
(valid_edges, obsolete_edges) = self._find_edges_status( (valid_edges, obsolete_edges) = self._find_edges_status(vertex,
vertex, neighbors) neighbors)
self._delete_old_connections(vertex, obsolete_edges) self._delete_old_connections(vertex, obsolete_edges)
self._connect_neighbors(neighbors, self._connect_neighbors(neighbors,
valid_edges, valid_edges,
@ -293,15 +293,15 @@ class Processor(processor.ProcessorBase):
longer connected to those entities), and which are valid connections. longer connected to those entities), and which are valid connections.
""" """
valid_edges = [] valid_edges = set()
obsolete_edges = [] obsolete_edges = set()
graph_neighbor_types = \ graph_neighbor_types = \
PUtils.find_neighbor_types(neighbors) PUtils.find_neighbor_types(neighbors)
for curr_edge in self.entity_graph.get_edges( neighbor_edges = set(e for v, e in neighbors)
vertex.vertex_id, for curr_edge in self.entity_graph.get_edges(vertex.vertex_id,
direction=Direction.BOTH): direction=Direction.BOTH):
# check if the edge in the graph has a a connection to the # check if the edge in the graph has a a connection to the
# same type of resources in the new neighbors list # same type of resources in the new neighbors list
neighbor_vertex = self.entity_graph.get_vertex( neighbor_vertex = self.entity_graph.get_vertex(
@ -311,14 +311,13 @@ class Processor(processor.ProcessorBase):
neighbor_vertex) in graph_neighbor_types neighbor_vertex) in graph_neighbor_types
if not is_connection_type_exist: if not is_connection_type_exist:
valid_edges.append(curr_edge) valid_edges.add(curr_edge)
continue continue
neighbor_edges = [e for v, e in neighbors]
if curr_edge in neighbor_edges: if curr_edge in neighbor_edges:
valid_edges.append(curr_edge) valid_edges.add(curr_edge)
else: else:
obsolete_edges.append(curr_edge) obsolete_edges.add(curr_edge)
return valid_edges, obsolete_edges return valid_edges, obsolete_edges
@ -457,7 +456,6 @@ class Processor(processor.ProcessorBase):
raise VitrageError( raise VitrageError(
'found too many vertices with same properties: %s ', 'found too many vertices with same properties: %s ',
vertex) vertex)
graph_vertex = None if not graph_vertices \ graph_vertex = None if not graph_vertices else graph_vertices[0]
else graph_vertices[0]
return graph_vertex return graph_vertex

View File

@ -134,14 +134,11 @@ class BaseApiTest(base.BaseTestCase):
if public_net: if public_net:
kwargs.update({"networks": [{'uuid': public_net['id']}]}) kwargs.update({"networks": [{'uuid': public_net['id']}]})
# public_net = self._get_public_network()
# nics = [{'net-id': public_net['id']}]
img = images_list.next() img = images_list.next()
resources = [self.nova_client.servers.create( resources = [self.nova_client.servers.create(
name='%s-%s' % ('vm', index), name='%s-%s' % ('vm', index),
flavor=flavors_list[0], flavor=flavors_list[0],
image=img, image=img,
# nics=nics,
**kwargs) for index in range(num_instances)] **kwargs) for index in range(num_instances)]
self._wait_for_status(30, self._wait_for_status(30,