Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The new approach involves adding a column to the Fragment table, storing the last path component (called xpath_component here). TODO description of new algorithmThe new column is indexed, to allow constant-time lookups.

idparent_idanchor_idxpathxpath_component
1NULL3/bookstorebookstore
213/bookstore/categories[@code='1']categories[@code='1']
323/bookstore/categories[@code='1']/books[@title='Matilda']books[@title='Matilda']
423/bookstore/categories[@code='1']/books[@title='The Gruffalo']books[@title='The Gruffalo']

The new approach will first look for "bookstore", and using that as the parent ID, look for ''categories[@code='1']", and using that as parent ID, look for "books" or xpath component starting with "books[", before finally applying leaf condition checks.

For example, given this Cps Path:

...

A PoC was developed so that performance could be compared against existing Cps Path Query algorithms.

Performance Improvement

As can be seen in the cases below, the existing algorithm using regex has linear time complexity, on the the size of the database. The new algorithm is constant time.

...

...

Query one device from many, using descendant cps path

In this case, a query that matches a single device node is executed, such as:

//openroadm-device[@device-id="C201-7-1A-14"]
none
Case
master645391,4511bnonepoc3328652a
Descendant Cps PathAbsolute Cps Path
Query//openroadm-device[@device-id="C201-7-1A-
25
14"]
directmaster875831,5802b3a/
directpoc343570
/openroadm-devices/openroadm-device[@device-id="C201-7-1A-
36
19"]
all
Graph
master

Image Added

926191,6933ballpoc5143674aQuery 1

Image Added

As seen in the graphs, query performance for current master branch is linear on the size of the database, while the PoC implementation is constant time.

Query one device from many, using absolute cps path

...

/openroadm-devices/openroadm-device[@device-id="C201-7-1A-19"]

...

In this case, a query that matches a single device node using an absolute cps path is executed, such as:

...

/openroadm-devices/openroadm-device[@device-id="C201-7-1A-

...

19"]

...


...

/openroadm-devices/openroadm-device[@device-id="C201-7-1A-46"]

...

As seen in the graph, query performance for current master branch is linear on the size of the database, while the PoC implementation is constant time.

Query many devices from many, using descendant cps path

...

//openroadm-device[@ne-state="inservice"]

...

//openroadm-device[@ne-state="inservice"]

...

In this case, a query that matches many device nodes using a descendant cps path is executed:

//openroadm-device[@ne-state="inservice"]
all
Omit Descendants
master

Direct Descendants

57712,02743,3219ballpoc2271,4503,50210a

All Descendants

Image Added

Image Added

Image Added



Image Added

Query many devices from many, using absolute cps path

...

/openroadm-devices/openroadm-device[@status="success"]

...

/openroadm-devices/openroadm-device[@status="success"]

...


Summary of performance

As can be seen in the cases below, the existing algorithm using regex has linear time complexity, on the the size of the database. The new algorithm is constant time.

  • For querying 1 out of many nodes, existing algorithm is linear
  • For querying 1 out of many nodes, new algorithm is constant
  • For querying many out of many nodes, existing algorithm is quadratic
  • For querying many out of many nodes, new algorithm is linear

Work Breakdown

In addition to the changes outlined above, there is additional work remaining for this change to be production-ready. 

The main algorithm was mostly done during the PoC (all integration tests are passing for the PoC). The existing PoC code can thus be refactored to make it production ready.

DB upgrade

Because a new column is being added to the Fragment table, this column needs to be populated. An SQL script will be needed to provide a value for of the new xpath_component field based on existing xpath field.

Cps Path Parser changes

CpsPathBuilder and CpsPathQuery classes from cps-path-parser module will need to be updated to provide the individual path components.

...

/openroadm-devices/openroadm-device[@status="success"]

...