From: Yevgeny Khodorkovsky Date: Wed, 31 Jul 2013 00:28:11 +0000 (-0700) Subject: Statistics Mgr to avoid unnucessary cache updates X-Git-Tag: releasepom-0.1.0~249 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=f6ca11900a9672d17193372376368e9ef130a28f Statistics Mgr to avoid unnucessary cache updates - Update cache only if stats value has changed since last update - Add hashcode and equals overrides to stats classes Change-Id: I6cbce35c26ec389efe26e7a53c886b9e4e580ed5 Signed-off-by: Yevgeny Khodorkovsky --- diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/reader/FlowOnNode.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/reader/FlowOnNode.java index 163d04b3ff..994ee4533e 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/reader/FlowOnNode.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/reader/FlowOnNode.java @@ -114,6 +114,56 @@ public class FlowOnNode implements Serializable{ this.durationNanoseconds = durationNanoseconds; } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (int) (byteCount ^ (byteCount >>> 32)); + result = prime * result + durationNanoseconds; + result = prime * result + durationSeconds; + result = prime * result + ((flow == null) ? 0 : flow.hashCode()); + result = prime * result + (int) (packetCount ^ (packetCount >>> 32)); + result = prime * result + tableId; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof FlowOnNode)) { + return false; + } + FlowOnNode other = (FlowOnNode) obj; + if (byteCount != other.byteCount) { + return false; + } + if (durationNanoseconds != other.durationNanoseconds) { + return false; + } + if (durationSeconds != other.durationSeconds) { + return false; + } + if (flow == null) { + if (other.flow != null) { + return false; + } + } else if (!flow.equals(other.flow)) { + return false; + } + if (packetCount != other.packetCount) { + return false; + } + if (tableId != other.tableId) { + return false; + } + return true; + } + @Override public String toString() { return "FlowOnNode[flow =" + flow + ", tableId = " + tableId diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/reader/NodeConnectorStatistics.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/reader/NodeConnectorStatistics.java index 848b19ee0f..fc6a6d87f1 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/reader/NodeConnectorStatistics.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/reader/NodeConnectorStatistics.java @@ -18,7 +18,7 @@ import javax.xml.bind.annotation.XmlRootElement; import org.opendaylight.controller.sal.core.NodeConnector; /** - * Represents the statistics for the node conenctor + * Represents the statistics for a node connector */ @XmlRootElement @XmlAccessorType(XmlAccessType.NONE) @@ -52,6 +52,84 @@ public class NodeConnectorStatistics implements Serializable { @XmlElement private long collisionCount; + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (int) (collisionCount ^ (collisionCount >>> 32)); + result = prime * result + ((nodeConnector == null) ? 0 : nodeConnector.hashCode()); + result = prime * result + (int) (receiveBytes ^ (receiveBytes >>> 32)); + result = prime * result + (int) (receiveCrcError ^ (receiveCrcError >>> 32)); + result = prime * result + (int) (receiveDrops ^ (receiveDrops >>> 32)); + result = prime * result + (int) (receiveErrors ^ (receiveErrors >>> 32)); + result = prime * result + (int) (receiveFrameError ^ (receiveFrameError >>> 32)); + result = prime * result + (int) (receiveOverRunError ^ (receiveOverRunError >>> 32)); + result = prime * result + (int) (receivePackets ^ (receivePackets >>> 32)); + result = prime * result + (int) (transmitBytes ^ (transmitBytes >>> 32)); + result = prime * result + (int) (transmitDrops ^ (transmitDrops >>> 32)); + result = prime * result + (int) (transmitErrors ^ (transmitErrors >>> 32)); + result = prime * result + (int) (transmitPackets ^ (transmitPackets >>> 32)); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof NodeConnectorStatistics)) { + return false; + } + NodeConnectorStatistics other = (NodeConnectorStatistics) obj; + if (collisionCount != other.collisionCount) { + return false; + } + if (nodeConnector == null) { + if (other.nodeConnector != null) { + return false; + } + } else if (!nodeConnector.equals(other.nodeConnector)) { + return false; + } + if (receiveBytes != other.receiveBytes) { + return false; + } + if (receiveCrcError != other.receiveCrcError) { + return false; + } + if (receiveDrops != other.receiveDrops) { + return false; + } + if (receiveErrors != other.receiveErrors) { + return false; + } + if (receiveFrameError != other.receiveFrameError) { + return false; + } + if (receiveOverRunError != other.receiveOverRunError) { + return false; + } + if (receivePackets != other.receivePackets) { + return false; + } + if (transmitBytes != other.transmitBytes) { + return false; + } + if (transmitDrops != other.transmitDrops) { + return false; + } + if (transmitErrors != other.transmitErrors) { + return false; + } + if (transmitPackets != other.transmitPackets) { + return false; + } + return true; + } + // To Satisfy JAXB public NodeConnectorStatistics() { diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/reader/NodeDescription.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/reader/NodeDescription.java index 8f99b05a09..12ce4d6948 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/reader/NodeDescription.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/reader/NodeDescription.java @@ -68,6 +68,68 @@ public class NodeDescription implements Serializable, Cloneable{ this.description = description; } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((hardware == null) ? 0 : hardware.hashCode()); + result = prime * result + ((manufacturer == null) ? 0 : manufacturer.hashCode()); + result = prime * result + ((serialNumber == null) ? 0 : serialNumber.hashCode()); + result = prime * result + ((software == null) ? 0 : software.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof NodeDescription)) { + return false; + } + NodeDescription other = (NodeDescription) obj; + if (description == null) { + if (other.description != null) { + return false; + } + } else if (!description.equals(other.description)) { + return false; + } + if (hardware == null) { + if (other.hardware != null) { + return false; + } + } else if (!hardware.equals(other.hardware)) { + return false; + } + if (manufacturer == null) { + if (other.manufacturer != null) { + return false; + } + } else if (!manufacturer.equals(other.manufacturer)) { + return false; + } + if (serialNumber == null) { + if (other.serialNumber != null) { + return false; + } + } else if (!serialNumber.equals(other.serialNumber)) { + return false; + } + if (software == null) { + if (other.software != null) { + return false; + } + } else if (!software.equals(other.software)) { + return false; + } + return true; + } + @Override public String toString() { return "HwDescription[manufacturer=" + manufacturer + ", hardware=" diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/reader/NodeTableStatistics.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/reader/NodeTableStatistics.java index 3b359cb812..7c404178cf 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/reader/NodeTableStatistics.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/reader/NodeTableStatistics.java @@ -39,6 +39,56 @@ public class NodeTableStatistics implements Serializable { private long matchedCount; + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + activeCount; + result = prime * result + (int) (lookupCount ^ (lookupCount >>> 32)); + result = prime * result + (int) (matchedCount ^ (matchedCount >>> 32)); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((nodeTable == null) ? 0 : nodeTable.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof NodeTableStatistics)) { + return false; + } + NodeTableStatistics other = (NodeTableStatistics) obj; + if (activeCount != other.activeCount) { + return false; + } + if (lookupCount != other.lookupCount) { + return false; + } + if (matchedCount != other.matchedCount) { + return false; + } + if (name == null) { + if (other.name != null) { + return false; + } + } else if (!name.equals(other.name)) { + return false; + } + if (nodeTable == null) { + if (other.nodeTable != null) { + return false; + } + } else if (!nodeTable.equals(other.nodeTable)) { + return false; + } + return true; + } + //To Satisfy JAXB public NodeTableStatistics() { diff --git a/opendaylight/statisticsmanager/implementation/src/main/java/org/opendaylight/controller/statisticsmanager/internal/StatisticsManager.java b/opendaylight/statisticsmanager/implementation/src/main/java/org/opendaylight/controller/statisticsmanager/internal/StatisticsManager.java index f5c13b6105..eec183d595 100644 --- a/opendaylight/statisticsmanager/implementation/src/main/java/org/opendaylight/controller/statisticsmanager/internal/StatisticsManager.java +++ b/opendaylight/statisticsmanager/implementation/src/main/java/org/opendaylight/controller/statisticsmanager/internal/StatisticsManager.java @@ -167,7 +167,7 @@ public class StatisticsManager implements IStatisticsManager, IReadServiceListen * Function called after registering the service in OSGi service registry. */ void started(){ - //retrieve current statistics so we don't have to wait for next refresh + // Retrieve current statistics so we don't have to wait for next refresh ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance( ISwitchManager.class, container.getName(), this); if (reader != null && switchManager != null) { @@ -180,7 +180,7 @@ public class StatisticsManager implements IStatisticsManager, IReadServiceListen } } else { - log.warn("Failed to retrieve current statistics. Statistics will not be immidiately available!"); + log.trace("Failed to retrieve current statistics. Statistics will not be immediately available!"); } } @@ -247,7 +247,7 @@ public class StatisticsManager implements IStatisticsManager, IReadServiceListen } Node node; - //index FlowEntries' flows by node so we don't traverse entire flow list for each flowEntry + // Index FlowEntries' flows by node so we don't traverse entire flow list for each flowEntry Map> index = new HashMap>(); for (FlowEntry flowEntry : flowList) { node = flowEntry.getNode(); @@ -256,7 +256,7 @@ public class StatisticsManager implements IStatisticsManager, IReadServiceListen index.put(node, set); } - //iterate over flows per indexed node and add to output + // Iterate over flows per indexed node and add to output for (Entry> indexEntry : index.entrySet()) { node = indexEntry.getKey(); List flowsPerNode = flowStatistics.get(node); @@ -356,27 +356,40 @@ public class StatisticsManager implements IStatisticsManager, IReadServiceListen @Override public void nodeFlowStatisticsUpdated(Node node, List flowStatsList) { - this.flowStatistics.put(node, flowStatsList); + List currentStat = this.flowStatistics.get(node); + // Update cache only if changed to avoid unnecessary cache sync operations + if (! flowStatsList.equals(currentStat)){ + this.flowStatistics.put(node, flowStatsList); + } } @Override public void nodeConnectorStatisticsUpdated(Node node, List ncStatsList) { - this.nodeConnectorStatistics.put(node, ncStatsList); + List currentStat = this.nodeConnectorStatistics.get(node); + if (! ncStatsList.equals(currentStat)){ + this.nodeConnectorStatistics.put(node, ncStatsList); + } } @Override public void nodeTableStatisticsUpdated(Node node, List tableStatsList) { - this.tableStatistics.put(node, tableStatsList); + List currentStat = this.tableStatistics.get(node); + if (! tableStatsList.equals(currentStat)) { + this.tableStatistics.put(node, tableStatsList); + } } @Override public void descriptionStatisticsUpdated(Node node, NodeDescription nodeDescription) { - this.descriptionStatistics.put(node, nodeDescription); + NodeDescription currentDesc = this.descriptionStatistics.get(node); + if (! nodeDescription.equals(currentDesc)){ + this.descriptionStatistics.put(node, nodeDescription); + } } @Override public void updateNode(Node node, UpdateType type, Set props) { - //if node is removed, remove stats mappings + // If node is removed, clean up stats mappings if (type == UpdateType.REMOVED) { flowStatistics.remove(node); nodeConnectorStatistics.remove(node); @@ -387,6 +400,6 @@ public class StatisticsManager implements IStatisticsManager, IReadServiceListen @Override public void updateNodeConnector(NodeConnector nodeConnector, UpdateType type, Set props) { - // not interested in this update + // Not interested in this update } }