Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9B7F21746B for ; Thu, 9 Apr 2015 11:36:06 +0000 (UTC) Received: (qmail 43737 invoked by uid 500); 9 Apr 2015 11:36:02 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 43549 invoked by uid 500); 9 Apr 2015 11:36:01 -0000 Mailing-List: contact commits-help@ignite.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.incubator.apache.org Delivered-To: mailing list commits@ignite.incubator.apache.org Received: (qmail 43481 invoked by uid 99); 9 Apr 2015 11:36:01 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Apr 2015 11:36:01 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 09 Apr 2015 11:35:58 +0000 Received: (qmail 36054 invoked by uid 99); 9 Apr 2015 11:35:35 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Apr 2015 11:35:35 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 97C52DFFCD; Thu, 9 Apr 2015 11:35:35 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: akuznetsov@apache.org To: commits@ignite.incubator.apache.org Date: Thu, 09 Apr 2015 11:35:56 -0000 Message-Id: <9fe2450598d0411dbefebd47a6e17463@git.apache.org> In-Reply-To: <4555c18fe0764c85bb241c5238bc8fed@git.apache.org> References: <4555c18fe0764c85bb241c5238bc8fed@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [22/50] [abbrv] incubator-ignite git commit: # IGNITE-30 Use ByteBuffer to serialize metrics. X-Virus-Checked: Checked by ClamAV on apache.org # IGNITE-30 Use ByteBuffer to serialize metrics. Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/cb21533e Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/cb21533e Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/cb21533e Branch: refs/heads/ignite-692 Commit: cb21533eb665776bcd11531f678b1e87b1d3951d Parents: 1e55e2d Author: sevdokimov Authored: Tue Apr 7 18:33:53 2015 +0300 Committer: sevdokimov Committed: Tue Apr 7 18:33:53 2015 +0300 ---------------------------------------------------------------------- .../ignite/internal/ClusterMetricsSnapshot.java | 384 ++++++------------- 1 file changed, 115 insertions(+), 269 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cb21533e/modules/core/src/main/java/org/apache/ignite/internal/ClusterMetricsSnapshot.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/ClusterMetricsSnapshot.java b/modules/core/src/main/java/org/apache/ignite/internal/ClusterMetricsSnapshot.java index 6e933ab..558b0c3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/ClusterMetricsSnapshot.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/ClusterMetricsSnapshot.java @@ -22,6 +22,7 @@ import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.jetbrains.annotations.*; +import java.nio.*; import java.util.*; import static java.lang.Math.*; @@ -1252,63 +1253,63 @@ public class ClusterMetricsSnapshot implements ClusterMetrics { * @return New offset. */ public static int serialize(byte[] data, int off, ClusterMetrics metrics) { - int start = off; - - off = U.intToBytes(metrics.getMaximumActiveJobs(), data, off); - off = U.intToBytes(metrics.getCurrentActiveJobs(), data, off); - off = U.floatToBytes(metrics.getAverageActiveJobs(), data, off); - off = U.intToBytes(metrics.getMaximumWaitingJobs(), data, off); - off = U.intToBytes(metrics.getCurrentWaitingJobs(), data, off); - off = U.floatToBytes(metrics.getAverageWaitingJobs(), data, off); - off = U.intToBytes(metrics.getMaximumRejectedJobs(), data, off); - off = U.intToBytes(metrics.getCurrentRejectedJobs(), data, off); - off = U.floatToBytes(metrics.getAverageRejectedJobs(), data, off); - off = U.intToBytes(metrics.getMaximumCancelledJobs(), data, off); - off = U.intToBytes(metrics.getCurrentCancelledJobs(), data, off); - off = U.floatToBytes(metrics.getAverageCancelledJobs(), data, off); - off = U.intToBytes(metrics.getTotalRejectedJobs(), data, off); - off = U.intToBytes(metrics.getTotalCancelledJobs(), data, off); - off = U.intToBytes(metrics.getTotalExecutedJobs(), data, off); - off = U.longToBytes(metrics.getMaximumJobWaitTime(), data, off); - off = U.longToBytes(metrics.getCurrentJobWaitTime(), data, off); - off = U.doubleToBytes(metrics.getAverageJobWaitTime(), data, off); - off = U.longToBytes(metrics.getMaximumJobExecuteTime(), data, off); - off = U.longToBytes(metrics.getCurrentJobExecuteTime(), data, off); - off = U.doubleToBytes(metrics.getAverageJobExecuteTime(), data, off); - off = U.intToBytes(metrics.getTotalExecutedTasks(), data, off); - off = U.longToBytes(metrics.getCurrentIdleTime(), data, off); - off = U.longToBytes(metrics.getTotalIdleTime(), data, off); - off = U.intToBytes(metrics.getTotalCpus(), data, off); - off = U.doubleToBytes(metrics.getCurrentCpuLoad(), data, off); - off = U.doubleToBytes(metrics.getAverageCpuLoad(), data, off); - off = U.doubleToBytes(metrics.getCurrentGcCpuLoad(), data, off); - off = U.longToBytes(metrics.getHeapMemoryInitialized(), data, off); - off = U.longToBytes(metrics.getHeapMemoryUsed(), data, off); - off = U.longToBytes(metrics.getHeapMemoryCommitted(), data, off); - off = U.longToBytes(metrics.getHeapMemoryMaximum(), data, off); - off = U.longToBytes(metrics.getHeapMemoryTotal(), data, off); - off = U.longToBytes(metrics.getNonHeapMemoryInitialized(), data, off); - off = U.longToBytes(metrics.getNonHeapMemoryUsed(), data, off); - off = U.longToBytes(metrics.getNonHeapMemoryCommitted(), data, off); - off = U.longToBytes(metrics.getNonHeapMemoryMaximum(), data, off); - off = U.longToBytes(metrics.getNonHeapMemoryTotal(), data, off); - off = U.longToBytes(metrics.getStartTime(), data, off); - off = U.longToBytes(metrics.getNodeStartTime(), data, off); - off = U.longToBytes(metrics.getUpTime(), data, off); - off = U.intToBytes(metrics.getCurrentThreadCount(), data, off); - off = U.intToBytes(metrics.getMaximumThreadCount(), data, off); - off = U.longToBytes(metrics.getTotalStartedThreadCount(), data, off); - off = U.intToBytes(metrics.getCurrentDaemonThreadCount(), data, off); - off = U.longToBytes(metrics.getLastDataVersion(), data, off); - off = U.intToBytes(metrics.getSentMessagesCount(), data, off); - off = U.longToBytes(metrics.getSentBytesCount(), data, off); - off = U.intToBytes(metrics.getReceivedMessagesCount(), data, off); - off = U.longToBytes(metrics.getReceivedBytesCount(), data, off); - off = U.intToBytes(metrics.getOutboundMessagesQueueSize(), data, off); - off = U.intToBytes(metrics.getTotalNodes(), data, off); - - assert off - start == METRICS_SIZE : "Invalid metrics size [expected=" + METRICS_SIZE + ", actual=" + - (off - start) + ']'; + ByteBuffer buf = ByteBuffer.wrap(data, off, METRICS_SIZE); + + buf.putInt(metrics.getMaximumActiveJobs()); + buf.putInt(metrics.getCurrentActiveJobs()); + buf.putFloat(metrics.getAverageActiveJobs()); + buf.putInt(metrics.getMaximumWaitingJobs()); + buf.putInt(metrics.getCurrentWaitingJobs()); + buf.putFloat(metrics.getAverageWaitingJobs()); + buf.putInt(metrics.getMaximumRejectedJobs()); + buf.putInt(metrics.getCurrentRejectedJobs()); + buf.putFloat(metrics.getAverageRejectedJobs()); + buf.putInt(metrics.getMaximumCancelledJobs()); + buf.putInt(metrics.getCurrentCancelledJobs()); + buf.putFloat(metrics.getAverageCancelledJobs()); + buf.putInt(metrics.getTotalRejectedJobs()); + buf.putInt(metrics.getTotalCancelledJobs()); + buf.putInt(metrics.getTotalExecutedJobs()); + buf.putLong(metrics.getMaximumJobWaitTime()); + buf.putLong(metrics.getCurrentJobWaitTime()); + buf.putDouble(metrics.getAverageJobWaitTime()); + buf.putLong(metrics.getMaximumJobExecuteTime()); + buf.putLong(metrics.getCurrentJobExecuteTime()); + buf.putDouble(metrics.getAverageJobExecuteTime()); + buf.putInt(metrics.getTotalExecutedTasks()); + buf.putLong(metrics.getCurrentIdleTime()); + buf.putLong(metrics.getTotalIdleTime()); + buf.putInt(metrics.getTotalCpus()); + buf.putDouble(metrics.getCurrentCpuLoad()); + buf.putDouble(metrics.getAverageCpuLoad()); + buf.putDouble(metrics.getCurrentGcCpuLoad()); + buf.putLong(metrics.getHeapMemoryInitialized()); + buf.putLong(metrics.getHeapMemoryUsed()); + buf.putLong(metrics.getHeapMemoryCommitted()); + buf.putLong(metrics.getHeapMemoryMaximum()); + buf.putLong(metrics.getHeapMemoryTotal()); + buf.putLong(metrics.getNonHeapMemoryInitialized()); + buf.putLong(metrics.getNonHeapMemoryUsed()); + buf.putLong(metrics.getNonHeapMemoryCommitted()); + buf.putLong(metrics.getNonHeapMemoryMaximum()); + buf.putLong(metrics.getNonHeapMemoryTotal()); + buf.putLong(metrics.getStartTime()); + buf.putLong(metrics.getNodeStartTime()); + buf.putLong(metrics.getUpTime()); + buf.putInt(metrics.getCurrentThreadCount()); + buf.putInt(metrics.getMaximumThreadCount()); + buf.putLong(metrics.getTotalStartedThreadCount()); + buf.putInt(metrics.getCurrentDaemonThreadCount()); + buf.putLong(metrics.getLastDataVersion()); + buf.putInt(metrics.getSentMessagesCount()); + buf.putLong(metrics.getSentBytesCount()); + buf.putInt(metrics.getReceivedMessagesCount()); + buf.putLong(metrics.getReceivedBytesCount()); + buf.putInt(metrics.getOutboundMessagesQueueSize()); + buf.putInt(metrics.getTotalNodes()); + + assert !buf.hasRemaining() : "Invalid metrics size [expected=" + METRICS_SIZE + ", actual=" + + (buf.position() - off) + ']'; return off; } @@ -1321,222 +1322,67 @@ public class ClusterMetricsSnapshot implements ClusterMetrics { * @return Deserialized node metrics. */ public static ClusterMetrics deserialize(byte[] data, int off) { - int start = off; - ClusterMetricsSnapshot metrics = new ClusterMetricsSnapshot(); - metrics.setLastUpdateTime(U.currentTimeMillis()); - - metrics.setMaximumActiveJobs(U.bytesToInt(data, off)); - - off += 4; - - metrics.setCurrentActiveJobs(U.bytesToInt(data, off)); - - off += 4; - - metrics.setAverageActiveJobs(U.bytesToFloat(data, off)); - - off += 4; - - metrics.setMaximumWaitingJobs(U.bytesToInt(data, off)); - - off += 4; - - metrics.setCurrentWaitingJobs(U.bytesToInt(data, off)); - - off += 4; - - metrics.setAverageWaitingJobs(U.bytesToFloat(data, off)); - - off += 4; - - metrics.setMaximumRejectedJobs(U.bytesToInt(data, off)); - - off += 4; - - metrics.setCurrentRejectedJobs(U.bytesToInt(data, off)); - - off += 4; - - metrics.setAverageRejectedJobs(U.bytesToFloat(data, off)); - - off += 4; - - metrics.setMaximumCancelledJobs(U.bytesToInt(data, off)); - - off += 4; - - metrics.setCurrentCancelledJobs(U.bytesToInt(data, off)); - - off += 4; - - metrics.setAverageCancelledJobs(U.bytesToFloat(data, off)); - - off += 4; - - metrics.setTotalRejectedJobs(U.bytesToInt(data, off)); - - off += 4; - - metrics.setTotalCancelledJobs(U.bytesToInt(data, off)); - - off += 4; - - metrics.setTotalExecutedJobs(U.bytesToInt(data, off)); - - off += 4; - - metrics.setMaximumJobWaitTime(U.bytesToLong(data, off)); - - off += 8; - - metrics.setCurrentJobWaitTime(U.bytesToLong(data, off)); - - off += 8; - - metrics.setAverageJobWaitTime(U.bytesToDouble(data, off)); - - off += 8; - - metrics.setMaximumJobExecuteTime(U.bytesToLong(data, off)); - - off += 8; - - metrics.setCurrentJobExecuteTime(U.bytesToLong(data, off)); - - off += 8; - - metrics.setAverageJobExecuteTime(U.bytesToDouble(data, off)); - - off += 8; - - metrics.setTotalExecutedTasks(U.bytesToInt(data, off)); - - off += 4; - - metrics.setCurrentIdleTime(U.bytesToLong(data, off)); - - off += 8; - - metrics.setTotalIdleTime(U.bytesToLong(data, off)); - - off += 8; - - metrics.setAvailableProcessors(U.bytesToInt(data, off)); - - off += 4; - - metrics.setCurrentCpuLoad(U.bytesToDouble(data, off)); + ByteBuffer buf = ByteBuffer.wrap(data, off, METRICS_SIZE); - off += 8; - - metrics.setAverageCpuLoad(U.bytesToDouble(data, off)); - - off += 8; - - metrics.setCurrentGcCpuLoad(U.bytesToDouble(data, off)); - - off += 8; - - metrics.setHeapMemoryInitialized(U.bytesToLong(data, off)); - - off += 8; - - metrics.setHeapMemoryUsed(U.bytesToLong(data, off)); - - off += 8; - - metrics.setHeapMemoryCommitted(U.bytesToLong(data, off)); - - off += 8; - - metrics.setHeapMemoryMaximum(U.bytesToLong(data, off)); - - off += 8; - - metrics.setHeapMemoryTotal(U.bytesToLong(data, off)); - - off += 8; - - metrics.setNonHeapMemoryInitialized(U.bytesToLong(data, off)); - - off += 8; - - metrics.setNonHeapMemoryUsed(U.bytesToLong(data, off)); - - off += 8; - - metrics.setNonHeapMemoryCommitted(U.bytesToLong(data, off)); - - off += 8; - - metrics.setNonHeapMemoryMaximum(U.bytesToLong(data, off)); - - off += 8; - - metrics.setNonHeapMemoryTotal(U.bytesToLong(data, off)); - - off += 8; - - metrics.setStartTime(U.bytesToLong(data, off)); - - off += 8; - - metrics.setNodeStartTime(U.bytesToLong(data, off)); - - off += 8; - - metrics.setUpTime(U.bytesToLong(data, off)); - - off += 8; - - metrics.setCurrentThreadCount(U.bytesToInt(data, off)); - - off += 4; - - metrics.setMaximumThreadCount(U.bytesToInt(data, off)); - - off += 4; - - metrics.setTotalStartedThreadCount(U.bytesToLong(data, off)); - - off += 8; - - metrics.setCurrentDaemonThreadCount(U.bytesToInt(data, off)); - - off += 4; - - metrics.setLastDataVersion(U.bytesToLong(data, off)); - - off += 8; - - metrics.setSentMessagesCount(U.bytesToInt(data, off)); - - off += 4; - - metrics.setSentBytesCount(U.bytesToLong(data, off)); - - off += 8; - - metrics.setReceivedMessagesCount(U.bytesToInt(data, off)); - - off += 4; - - metrics.setReceivedBytesCount(U.bytesToLong(data, off)); - - off += 8; - - metrics.setOutboundMessagesQueueSize(U.bytesToInt(data, off)); - - off += 4; - - metrics.setTotalNodes(U.bytesToInt(data, off)); - - off += 4; + metrics.setLastUpdateTime(U.currentTimeMillis()); - assert off - start == METRICS_SIZE : "Invalid metrics size [expected=" + METRICS_SIZE + ", actual=" + - (off - start) + ']'; + metrics.setMaximumActiveJobs(buf.getInt()); + metrics.setCurrentActiveJobs(buf.getInt()); + metrics.setAverageActiveJobs(buf.getFloat()); + metrics.setMaximumWaitingJobs(buf.getInt()); + metrics.setCurrentWaitingJobs(buf.getInt()); + metrics.setAverageWaitingJobs(buf.getFloat()); + metrics.setMaximumRejectedJobs(buf.getInt()); + metrics.setCurrentRejectedJobs(buf.getInt()); + metrics.setAverageRejectedJobs(buf.getFloat()); + metrics.setMaximumCancelledJobs(buf.getInt()); + metrics.setCurrentCancelledJobs(buf.getInt()); + metrics.setAverageCancelledJobs(buf.getFloat()); + metrics.setTotalRejectedJobs(buf.getInt()); + metrics.setTotalCancelledJobs(buf.getInt()); + metrics.setTotalExecutedJobs(buf.getInt()); + metrics.setMaximumJobWaitTime(buf.getLong()); + metrics.setCurrentJobWaitTime(buf.getLong()); + metrics.setAverageJobWaitTime(buf.getDouble()); + metrics.setMaximumJobExecuteTime(buf.getLong()); + metrics.setCurrentJobExecuteTime(buf.getLong()); + metrics.setAverageJobExecuteTime(buf.getDouble()); + metrics.setTotalExecutedTasks(buf.getInt()); + metrics.setCurrentIdleTime(buf.getLong()); + metrics.setTotalIdleTime(buf.getLong()); + metrics.setAvailableProcessors(buf.getInt()); + metrics.setCurrentCpuLoad(buf.getDouble()); + metrics.setAverageCpuLoad(buf.getDouble()); + metrics.setCurrentGcCpuLoad(buf.getDouble()); + metrics.setHeapMemoryInitialized(buf.getLong()); + metrics.setHeapMemoryUsed(buf.getLong()); + metrics.setHeapMemoryCommitted(buf.getLong()); + metrics.setHeapMemoryMaximum(buf.getLong()); + metrics.setHeapMemoryTotal(buf.getLong()); + metrics.setNonHeapMemoryInitialized(buf.getLong()); + metrics.setNonHeapMemoryUsed(buf.getLong()); + metrics.setNonHeapMemoryCommitted(buf.getLong()); + metrics.setNonHeapMemoryMaximum(buf.getLong()); + metrics.setNonHeapMemoryTotal(buf.getLong()); + metrics.setStartTime(buf.getLong()); + metrics.setNodeStartTime(buf.getLong()); + metrics.setUpTime(buf.getLong()); + metrics.setCurrentThreadCount(buf.getInt()); + metrics.setMaximumThreadCount(buf.getInt()); + metrics.setTotalStartedThreadCount(buf.getLong()); + metrics.setCurrentDaemonThreadCount(buf.getInt()); + metrics.setLastDataVersion(buf.getLong()); + metrics.setSentMessagesCount(buf.getInt()); + metrics.setSentBytesCount(buf.getLong()); + metrics.setReceivedMessagesCount(buf.getInt()); + metrics.setReceivedBytesCount(buf.getLong()); + metrics.setOutboundMessagesQueueSize(buf.getInt()); + metrics.setTotalNodes(buf.getInt()); + + assert !buf.hasRemaining() : "Invalid metrics size [expected=" + METRICS_SIZE + ", actual=" + + (buf.position() - off) + ']'; return metrics; }