summaryrefslogtreecommitdiffstats
path: root/aai-core/src/main/java/org/onap/aai/serialization/engines/query/QueryEngine.java
diff options
context:
space:
mode:
authorKajur, Harish (vk250x) <vk250x@att.com>2018-12-04 14:06:14 -0500
committerKajur, Harish (vk250x) <vk250x@att.com>2018-12-05 09:38:36 -0500
commit8fb7aa6480d4d7becbbab5fcfabd6af3f57e7d74 (patch)
treee6cb6aa0e6839100a06a787c8ff3034aac11dbfb /aai-core/src/main/java/org/onap/aai/serialization/engines/query/QueryEngine.java
parent7bc1735a516e56d837aa5af3d4849cdcb7af26c7 (diff)
Improve the performance of resoures microservice1.4.0
Currently the findSubGraph is being invoked and causing additional calls to the database by backing a tree backed vertex and slowing the performance of GET ALLs Original intention of both of them was to pre fetch depth 0, 1, and 2 at once so we don't have to get them at each depth but since that was not done right there is extra amount of time After the aai-uri migration to ensure all vertexes have the aai-uri and also to make sure they are unique across graph we don't need to traverse a vertex to find the parents to build aai-uri it was done previously when there was no aai-uri to derive the uri of a given vertex and its not necessary anymore so there would be performance improvements of vserver when there are a lot of relationships Currently the edge labels are retrieved for each vertex a and b and the performance of the GET with relationships will be propotional to the GET request and how many cousin edges it has and the more cousin edges there are the more slower the response time will be as for each cousin vertex its trying to get the edge in between so the code is modified to only go to the database for the edge label when there are multiple edge labels (cousin edges) between a and b If there are only one edge label and its a cousin vertex then we can use the edge rule to be able to figure out the edge label Improve PUT on the cloud region by modifying the getEdgesBetween method which currently was retrieving all the parent child edges between a and b and then only using the first edge The traversal itself was too complicated and was costly in terms of database retrieval and calls and optimized the code to utilize the edge information so we can modify the query to db at runtime based on the information provided so when a 10000 vservers under a tenant adding a new vserver under tenant would be slow because of the old query performance as it was taking some time there but with this optimization, its only spending at most a millisecond or 2 in that method Also noticed that when a PUT operation takes place, the method calls the related objects to create a dmaap event which was in turn calling the findParents and actually utilizing the parents to create the dmaap event and would spend quite a lot of time here because of the expensive call of the findParents in this case we need those vertexes So optimized the code so based on a given vertex, we have the aai-uri and the newly added metadata uriTemplate to break the aai-uri into its parent aai-uri and grand parent aai-uri and so forth With this breakdown, we can get the list of aai-uris which are parents, grandparents and then use the aai-uri to look them up which is O(1) lookup time due to the fact they are unique indexes The time it takes when doing a traversal to find the parents is propotional to the number of edges but this will be optimistic Another area which was improved was the json path execution of the edge rules so when the edge rules get loaded into memory it creates a document object, it utilizes the jsonpath to query information about the edge rules but the only thing here is each time it gets called the query gets invoked and uses jsonpath to retrieve the edge rules when we can cached them based on the filter so that the user executed and if the filter is the same as before, the expected edge rules will return the same Too much time was spent making the query and retrieving and building the edgerules So a cache is a perfect way to optimize this part Issue-ID: AAI-1987 Change-Id: Ieb8237de3fd31136ceac14bf4a8216a7ab3b7179 Signed-off-by: Kajur, Harish (vk250x) <vk250x@att.com>
Diffstat (limited to 'aai-core/src/main/java/org/onap/aai/serialization/engines/query/QueryEngine.java')
-rw-r--r--aai-core/src/main/java/org/onap/aai/serialization/engines/query/QueryEngine.java57
1 files changed, 37 insertions, 20 deletions
diff --git a/aai-core/src/main/java/org/onap/aai/serialization/engines/query/QueryEngine.java b/aai-core/src/main/java/org/onap/aai/serialization/engines/query/QueryEngine.java
index c2929468..110f8628 100644
--- a/aai-core/src/main/java/org/onap/aai/serialization/engines/query/QueryEngine.java
+++ b/aai-core/src/main/java/org/onap/aai/serialization/engines/query/QueryEngine.java
@@ -42,16 +42,33 @@ public abstract class QueryEngine {
public QueryEngine (GraphTraversalSource g) {
this.g = g;
}
-
+
/**
* Finds all the parents/grandparents/etc of the given start node.
*
* @param start - the start vertex whose parent chain you want
* @return the list of start and start's parent, grandparent, etc, in
- * order (ie {start, parent, grandparent, etc}
+ * order (ie {start, parent, grandparent, etc}
*/
public abstract List<Vertex> findParents(Vertex start);
-
+
+ /**
+ * Finds all the parents/grandparents/etc of the given start node.
+ *
+ * This method should be used in place of the #findParents(Vertex)
+ * as since the aai-uri is added the lookup for finding the parents
+ * using the given list of aai-uri will be much faster than using
+ * a traversal to follow a start vertex and keep repeating since
+ * as the number of different type of edges keeps growing that call
+ * will be more expensive than using the aai-uri's as they are fast lookup
+ *
+ * @param uris - list of the uris representing the aai-uris of
+ * parent, grandparent, etc
+ * @return the list of start and start's parent, grandparent, etc, in
+ * order (ie {start, parent, grandparent, etc}
+ */
+ public abstract List<Vertex> findParents(String [] uris);
+
/**
* Finds all children, grandchildren, etc of start
*
@@ -59,7 +76,7 @@ public abstract class QueryEngine {
* @return the list of child/grandchild/etc vertices
*/
public abstract List<Vertex> findAllChildren(Vertex start);
-
+
/**
* Finds all immediate children of start (no grandchildren or so forth) of the given type
* @param start - the start vertex
@@ -67,14 +84,14 @@ public abstract class QueryEngine {
* @return the list of immediate child vertices of given type
*/
public abstract List<Vertex> findChildrenOfType(Vertex start, String type);
-
+
/**
* Finds all immediate children of start (no grandchildren or so forth)
* @param start - the start vertex
* @return the list of immediate child vertices
*/
public abstract List<Vertex> findChildren(Vertex start);
-
+
/**
* Find all vertices that should be deleted in a cascade from a delete of start
*
@@ -82,34 +99,34 @@ public abstract class QueryEngine {
* @return the list of vertices to be deleted when start is deleted
*/
public abstract List<Vertex> findDeletable(Vertex start);
-
+
/**
* Finds the subgraph under start, including cousins as well as start's children/grandchildren/etc.
* More specifically, this includes start, all its descendants, start's cousins, and start's
* descendants' cousins (but not any of the cousins' cousins or descendants), and the edges
* connecting them.
- *
+ *
* @param start - the start vertex
- * @return - Tree containing nodes and edges of the subgraph
+ * @return - Tree containing nodes and edges of the subgraph
*/
public Tree<Element> findSubGraph(Vertex start) {
return findSubGraph(start, AAIProperties.MAXIMUM_DEPTH, false);
}
-
+
/**
* Finds the subgraph under start, including cousins as well as start's children/grandchildren/etc.
* More specifically, this includes start, all its descendants, start's cousins, and start's
* descendants' cousins (but not any of the cousins' cousins or descendants), and the edges
* connecting them.
- *
+ *
* @param start - the start vertex
- * @param iterations - depth of the subgraph, this limits how many generations of
+ * @param iterations - depth of the subgraph, this limits how many generations of
* descendants are included
* @param nodeOnly - if true the subgraph will NOT include the cousins
- * @return Tree containing nodes and edges of the subgraph
+ * @return Tree containing nodes and edges of the subgraph
*/
public abstract Tree<Element> findSubGraph(Vertex start, int iterations, boolean nodeOnly);
-
+
/**
* Find vertices of type nodeType related to start by edges of the given
* direction and label.
@@ -125,23 +142,23 @@ public abstract class QueryEngine {
/**
* Finds cousin edges connecting start to other vertices only of types defined in an old version.
* The idea is that if a user is using an old version, they won't understand any new node types in
- * subsequent versions. Thus, revealing edges to new types will cause problems. This methods
+ * subsequent versions. Thus, revealing edges to new types will cause problems. This methods
* filters any such edges out.
- *
+ *
* @param start - the start vertex
* @param loader - loader for retrieving the list of allowed node types for the desired version
* (version is set when the loader was instantiated)
* @return list of cousin edges between start and any node types understood by the version specified in loader
*/
public abstract List<Edge> findEdgesForVersion(Vertex start, Loader loader);
-
+
/**
- * Finds all cousins of start.
- *
+ * Finds all cousins of start.
+ *
* @param start - the start vertex
* @return list of start's cousin vertices
*/
- public abstract List<Vertex> findCousinVertices(Vertex start);
+ public abstract List<Vertex> findCousinVertices(Vertex start, String... labels);
public abstract double getDBTimeMsecs();