You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by md...@apache.org on 2017/03/23 16:17:33 UTC

svn commit: r1788275 - in /jackrabbit/oak/trunk/oak-segment-tar/src: main/java/org/apache/jackrabbit/oak/segment/ main/java/org/apache/jackrabbit/oak/segment/file/ test/java/org/apache/jackrabbit/oak/segment/ test/java/org/apache/jackrabbit/oak/segment...

Author: mduerig
Date: Thu Mar 23 16:17:33 2017
New Revision: 1788275

URL: http://svn.apache.org/viewvc?rev=1788275&view=rev
Log:
OAK-5634: Expose IOMonitor stats via JMX
Implemented MetricsIOMonitor exposing read/write counts, volume and times

Added:
    jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/MetricsIOMonitor.java
    jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/MetricsIOMonitorTest.java
Modified:
    jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreService.java
    jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentCompactionIT.java

Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreService.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreService.java?rev=1788275&r1=1788274&r2=1788275&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreService.java (original)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreService.java Thu Mar 23 16:17:33 2017
@@ -118,6 +118,7 @@ import org.apache.jackrabbit.oak.segment
 import org.apache.jackrabbit.oak.segment.file.FileStoreGCMonitor;
 import org.apache.jackrabbit.oak.segment.file.FileStoreStatsMBean;
 import org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException;
+import org.apache.jackrabbit.oak.segment.file.MetricsIOMonitor;
 import org.apache.jackrabbit.oak.spi.blob.BlobStore;
 import org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore;
 import org.apache.jackrabbit.oak.spi.gc.GCMonitor;
@@ -448,6 +449,7 @@ public class SegmentNodeStoreService {
                 .withMaxFileSize(configuration.getMaxFileSize())
                 .withMemoryMapping(configuration.getMemoryMapping())
                 .withGCMonitor(gcMonitor)
+                .withIOMonitor(new MetricsIOMonitor(statisticsProvider))
                 .withStatisticsProvider(statisticsProvider)
                 .withGCOptions(gcOptions);
 

Added: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/MetricsIOMonitor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/MetricsIOMonitor.java?rev=1788275&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/MetricsIOMonitor.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/MetricsIOMonitor.java Thu Mar 23 16:17:33 2017
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.jackrabbit.oak.segment.file;
+
+import static java.util.concurrent.TimeUnit.NANOSECONDS;
+
+import java.io.File;
+
+import javax.annotation.Nonnull;
+
+import org.apache.jackrabbit.oak.stats.MeterStats;
+import org.apache.jackrabbit.oak.stats.StatisticsProvider;
+import org.apache.jackrabbit.oak.stats.StatsOptions;
+import org.apache.jackrabbit.oak.stats.TimerStats;
+
+/**
+ * This {@code IOMonitor} implementations registers the following monitoring endpoints
+ * with the Metrics library if available:
+ * <ul>
+ *     <li>{@link #OAK_SEGMENT_SEGMENT_READ_BYTES}:
+ *          a meter metrics for the number of bytes read from tar files</li>
+ *     <li>{@link #OAK_SEGMENT_SEGMENT_WRITE_BYTES}:
+ *          a meter metrics for the number of bytes written to tar files</li>
+ *     <li>{@link #OAK_SEGMENT_SEGMENT_READ_TIME}:
+ *          a timer metrics for the time spent reading from tar files</li>
+ *     <li>{@link #OAK_SEGMENT_SEGMENT_WRITE_TIME}:
+ *          a timer metrics for the time spent writing to tar files</li>
+ * </ul>
+ */
+public class MetricsIOMonitor extends IOMonitorAdapter {
+    public static final String OAK_SEGMENT_SEGMENT_READ_BYTES = "oak.segment.segment-read-bytes";
+    public static final String OAK_SEGMENT_SEGMENT_WRITE_BYTES = "oak.segment.segment-write-bytes";
+    public static final String OAK_SEGMENT_SEGMENT_READ_TIME = "oak.segment.segment-read-time";
+    public static final String OAK_SEGMENT_SEGMENT_WRITE_TIME = "oak.segment.segment-write-time";
+
+    private final MeterStats segmentReadBytes;
+    private final MeterStats segmentWriteBytes;
+    private final TimerStats segmentReadTime;
+    private final TimerStats segmentWriteTime;
+
+    public MetricsIOMonitor(@Nonnull StatisticsProvider statisticsProvider) {
+        segmentReadBytes = statisticsProvider.getMeter(
+                OAK_SEGMENT_SEGMENT_READ_BYTES, StatsOptions.METRICS_ONLY);
+        segmentWriteBytes = statisticsProvider.getMeter(
+                OAK_SEGMENT_SEGMENT_WRITE_BYTES, StatsOptions.METRICS_ONLY);
+        segmentReadTime = statisticsProvider.getTimer(
+                OAK_SEGMENT_SEGMENT_READ_TIME, StatsOptions.METRICS_ONLY);
+        segmentWriteTime = statisticsProvider.getTimer(
+                OAK_SEGMENT_SEGMENT_WRITE_TIME, StatsOptions.METRICS_ONLY);
+    }
+
+    @Override
+    public void afterSegmentRead(File file, long msb, long lsb, int length, long elapsed) {
+        segmentReadBytes.mark(length);
+        segmentReadTime.update(elapsed, NANOSECONDS);
+    }
+
+    @Override
+    public void afterSegmentWrite(File file, long msb, long lsb, int length, long elapsed) {
+        segmentWriteBytes.mark(length);
+        segmentWriteTime.update(elapsed, NANOSECONDS);
+    }
+}

Modified: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentCompactionIT.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentCompactionIT.java?rev=1788275&r1=1788274&r2=1788275&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentCompactionIT.java (original)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentCompactionIT.java Thu Mar 23 16:17:33 2017
@@ -85,6 +85,7 @@ import org.apache.jackrabbit.oak.segment
 import org.apache.jackrabbit.oak.segment.file.FileStore;
 import org.apache.jackrabbit.oak.segment.file.FileStoreBuilder;
 import org.apache.jackrabbit.oak.segment.file.FileStoreGCMonitor;
+import org.apache.jackrabbit.oak.segment.file.MetricsIOMonitor;
 import org.apache.jackrabbit.oak.spi.commit.CommitHook;
 import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
 import org.apache.jackrabbit.oak.spi.commit.CompositeHook;
@@ -234,6 +235,7 @@ public class SegmentCompactionIT {
                 .withMemoryMapping(true)
                 .withGCMonitor(gcMonitor)
                 .withGCOptions(gcOptions)
+                .withIOMonitor(new MetricsIOMonitor(statisticsProvider))
                 .withStatisticsProvider(statisticsProvider)
                 .build();
         nodeStore = SegmentNodeStoreBuilders.builder(fileStore)

Added: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/MetricsIOMonitorTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/MetricsIOMonitorTest.java?rev=1788275&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/MetricsIOMonitorTest.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/MetricsIOMonitorTest.java Thu Mar 23 16:17:33 2017
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.jackrabbit.oak.segment.file;
+
+import static org.apache.jackrabbit.oak.segment.file.MetricsIOMonitor.OAK_SEGMENT_SEGMENT_READ_BYTES;
+import static org.apache.jackrabbit.oak.segment.file.MetricsIOMonitor.OAK_SEGMENT_SEGMENT_READ_TIME;
+import static org.apache.jackrabbit.oak.segment.file.MetricsIOMonitor.OAK_SEGMENT_SEGMENT_WRITE_BYTES;
+import static org.apache.jackrabbit.oak.segment.file.MetricsIOMonitor.OAK_SEGMENT_SEGMENT_WRITE_TIME;
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+
+import org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser;
+import org.apache.jackrabbit.oak.stats.DefaultStatisticsProvider;
+import org.apache.jackrabbit.oak.stats.MeterStats;
+import org.apache.jackrabbit.oak.stats.StatsOptions;
+import org.apache.jackrabbit.oak.stats.TimerStats;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class MetricsIOMonitorTest {
+    private ScheduledExecutorService executor;
+
+    private MeterStats segmentReadBytes;
+    private MeterStats segmentWriteBytes;
+    private TimerStats segmentReadTime;
+    private TimerStats segmentWriteTime;
+
+    @Before
+    public void setup() {
+        executor = Executors.newSingleThreadScheduledExecutor();
+        DefaultStatisticsProvider statisticsProvider = new DefaultStatisticsProvider(executor);
+        MetricsIOMonitor ioMonitor = new MetricsIOMonitor(statisticsProvider);
+        segmentReadBytes = statisticsProvider.getMeter(
+                OAK_SEGMENT_SEGMENT_READ_BYTES, StatsOptions.METRICS_ONLY);
+        segmentWriteBytes = statisticsProvider.getMeter(
+                OAK_SEGMENT_SEGMENT_WRITE_BYTES, StatsOptions.METRICS_ONLY);
+        segmentReadTime = statisticsProvider.getTimer(
+                OAK_SEGMENT_SEGMENT_READ_TIME, StatsOptions.METRICS_ONLY);
+        segmentWriteTime = statisticsProvider.getTimer(
+                OAK_SEGMENT_SEGMENT_WRITE_TIME, StatsOptions.METRICS_ONLY);
+
+        File file = new File("");
+        ioMonitor.afterSegmentRead(file, 0, 0, 4, 0);
+        ioMonitor.afterSegmentRead(file, 0, 0, 5, 0);
+        ioMonitor.afterSegmentWrite(file, 0, 0, 3, 0);
+        ioMonitor.afterSegmentWrite(file, 0, 0, 4, 0);
+    }
+
+    @After
+    public void tearDown() {
+        new ExecutorCloser(executor).close();
+    }
+
+    @Test
+    public void testStats() {
+        assertEquals(9, segmentReadBytes.getCount());
+        assertEquals(2, segmentReadTime.getCount());
+        assertEquals(7, segmentWriteBytes.getCount());
+        assertEquals(2, segmentWriteTime.getCount());
+    }
+}