Repository: cassandra
Updated Branches:
  refs/heads/trunk 860291872 -> a0a949440


Add the metrics to track the write amplification of C*.

Patch by Dikang Gu; reviewed by marcuse for CASSANDRA-11420


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/a0a94944
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/a0a94944
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/a0a94944

Branch: refs/heads/trunk
Commit: a0a949440e9025300e4574a07628cbe5a95e517c
Parents: 8602918
Author: Dikang Gu <[email protected]>
Authored: Wed Mar 23 17:04:36 2016 -0700
Committer: Marcus Eriksson <[email protected]>
Committed: Tue Mar 29 09:16:17 2016 +0200

----------------------------------------------------------------------
 CHANGES.txt                                                    | 1 +
 src/java/org/apache/cassandra/db/Memtable.java                 | 5 ++++-
 .../org/apache/cassandra/db/compaction/CompactionTask.java     | 3 +++
 src/java/org/apache/cassandra/metrics/TableMetrics.java        | 6 ++++++
 4 files changed, 14 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/a0a94944/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 307f8ab..d8fe692 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.6
+ * Add metrics to track write amplification (CASSANDRA-11420)
  * cassandra-stress: cannot handle "value-less" tables (CASSANDRA-7739)
  * Add/drop multiple columns in one ALTER TABLE statement (CASSANDRA-10411)
  * Add require_endpoint_verification opt for internode encryption 
(CASSANDRA-9220)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/a0a94944/src/java/org/apache/cassandra/db/Memtable.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/Memtable.java 
b/src/java/org/apache/cassandra/db/Memtable.java
index 244c7b6..466e059 100644
--- a/src/java/org/apache/cassandra/db/Memtable.java
+++ b/src/java/org/apache/cassandra/db/Memtable.java
@@ -430,10 +430,13 @@ public class Memtable implements Comparable<Memtable>
                 }
             }
 
+            long bytesFlushed = writer.getFilePointer();
             logger.debug(String.format("Completed flushing %s (%s) for 
commitlog position %s",
                                                                               
writer.getFilename(),
-                                                                              
FBUtilities.prettyPrintMemory(writer.getFilePointer()),
+                                                                              
FBUtilities.prettyPrintMemory(bytesFlushed),
                                                                               
context));
+            // Update the metrics
+            cfs.metric.bytesFlushed.inc(bytesFlushed);
 
             if (heavilyContendedRowCount > 0)
                 logger.trace(String.format("High update contention in %d/%d 
partitions of %s ", heavilyContendedRowCount, toFlush.size(), 
Memtable.this.toString()));

http://git-wip-us.apache.org/repos/asf/cassandra/blob/a0a94944/src/java/org/apache/cassandra/db/compaction/CompactionTask.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/compaction/CompactionTask.java 
b/src/java/org/apache/cassandra/db/compaction/CompactionTask.java
index 9f02859..4cbfc28 100644
--- a/src/java/org/apache/cassandra/db/compaction/CompactionTask.java
+++ b/src/java/org/apache/cassandra/db/compaction/CompactionTask.java
@@ -223,6 +223,9 @@ public class CompactionTask extends AbstractCompactionTask
             logger.trace(String.format("CF Total Bytes Compacted: %,d", 
CompactionTask.addToTotalBytesCompacted(endsize)));
             logger.trace("Actual #keys: {}, Estimated #keys:{}, Err%: {}", 
totalKeysWritten, estimatedKeys, ((double)(totalKeysWritten - 
estimatedKeys)/totalKeysWritten));
 
+            // update the metrics
+            cfs.metric.compactionBytesWritten.inc(endsize);
+
             if (transaction.isOffline())
                 Refs.release(Refs.selfRefs(newSStables));
         }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/a0a94944/src/java/org/apache/cassandra/metrics/TableMetrics.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/metrics/TableMetrics.java 
b/src/java/org/apache/cassandra/metrics/TableMetrics.java
index 6492833..4282e16 100644
--- a/src/java/org/apache/cassandra/metrics/TableMetrics.java
+++ b/src/java/org/apache/cassandra/metrics/TableMetrics.java
@@ -79,6 +79,10 @@ public class TableMetrics
     public final LatencyMetrics writeLatency;
     /** Estimated number of tasks pending for this table */
     public final Counter pendingFlushes;
+    /** Total number of bytes flushed since server [re]start */
+    public final Counter bytesFlushed;
+    /** Total number of bytes written by compaction since server [re]start */
+    public final Counter compactionBytesWritten;
     /** Estimate of number of pending compactios for this table */
     public final Gauge<Integer> pendingCompactions;
     /** Number of SSTables on disk for this CF */
@@ -343,6 +347,8 @@ public class TableMetrics
         writeLatency = new LatencyMetrics(factory, "Write", 
cfs.keyspace.metric.writeLatency, globalWriteLatency);
         rangeLatency = new LatencyMetrics(factory, "Range", 
cfs.keyspace.metric.rangeLatency, globalRangeLatency);
         pendingFlushes = createTableCounter("PendingFlushes");
+        bytesFlushed = createTableCounter("BytesFlushed");
+        compactionBytesWritten = createTableCounter("CompactionBytesWritten");
         pendingCompactions = createTableGauge("PendingCompactions", new 
Gauge<Integer>()
         {
             public Integer getValue()

Reply via email to