[VOL-2688] Improve core model performance
This commit addresses the low-hanging performance hogs in the
core model. In particular, the following changes are made:
1) Remove proto message comparision when it's possible. The proto
message deep comparison is quite expensive.
2) Since the Core already has a lock on the device/logicaldevice/
adapters/etc before invoking the model proxy then there is no
need for the latter to create an additional lock on these artifacts
duting an update
3) The model creates a watch on every artifacts it adds to the KV
store. Since in the next Voltha release we will not be using Voltha
Core in pairs then there is no point in keeping these watches (these
is only 1 Core that will ever update an artifact in the next
deployment). This update removes these watch.
4) Additional unit tests has been created, mostly around flows, in an
attempt to exercise both the core and the model further.
Change-Id: Ieaf1f6b9b05c56e819600bc55b46a05f73b8efcf
diff --git a/db/model/non_persisted_revision.go b/db/model/non_persisted_revision.go
index 347be0d..20aeec3 100644
--- a/db/model/non_persisted_revision.go
+++ b/db/model/non_persisted_revision.go
@@ -384,29 +384,10 @@
// Does the existing list contain a child with that name?
if nameExists {
- // Check if the data has changed or not
- if existingChildren[nameIndex].GetData().(proto.Message).String() != newChild.GetData().(proto.Message).String() {
- log.Debugw("replacing-existing-child", log.Fields{
- "old-hash": existingChildren[nameIndex].GetHash(),
- "old-data": existingChildren[nameIndex].GetData(),
- "new-hash": newChild.GetHash(),
- "new-data": newChild.GetData(),
- })
-
- // replace entry
- newChild.getNode().SetRoot(existingChildren[nameIndex].getNode().GetRoot())
- updatedChildren = append(updatedChildren, newChild)
- } else {
- log.Debugw("keeping-existing-child", log.Fields{
- "old-hash": existingChildren[nameIndex].GetHash(),
- "old-data": existingChildren[nameIndex].GetData(),
- "new-hash": newChild.GetHash(),
- "new-data": newChild.GetData(),
- })
-
- // keep existing entry
- updatedChildren = append(updatedChildren, existingChildren[nameIndex])
- }
+ // This function is invoked only when the data has actually changed (current Core usage). Therefore,
+ // we need to avoid an expensive deep proto.message comparison and treat the data as an update
+ newChild.getNode().SetRoot(existingChildren[nameIndex].getNode().GetRoot())
+ updatedChildren = append(updatedChildren, newChild)
} else {
log.Debugw("adding-unknown-child", log.Fields{
"hash": newChild.GetHash(),