jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1565276 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/api/jmx/ oak-core/src/main/java/org/apache/jackrabbit/oak/stats/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/ oak-jcr/src/main/java/org/a...
Date Thu, 06 Feb 2014 14:29:29 GMT
Author: mduerig
Date: Thu Feb  6 14:29:28 2014
New Revision: 1565276

URL: http://svn.apache.org/r1565276
Log:
OAK-1338: Implement QueryStat from Jackrabbit API
Implement repository statistics: session read and write statistics

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/jmx/RepositoryStatsMBean.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/stats/RepositoryStats.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/repository/RepositoryImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/jmx/RepositoryStatsMBean.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/jmx/RepositoryStatsMBean.java?rev=1565276&r1=1565275&r2=1565276&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/jmx/RepositoryStatsMBean.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/jmx/RepositoryStatsMBean.java
Thu Feb  6 14:29:28 2014
@@ -39,4 +39,49 @@ public interface RepositoryStatsMBean {
      * @see org.apache.jackrabbit.api.stats.RepositoryStatistics.Type#SESSION_LOGIN_COUNTER
      */
     CompositeData getSessionLogin();
+
+    /**
+     * @see org.apache.jackrabbit.api.stats.RepositoryStatistics.Type#SESSION_READ_COUNTER
+     */
+    CompositeData getSessionReadCount();
+
+    /**
+     * @see org.apache.jackrabbit.api.stats.RepositoryStatistics.Type#SESSION_READ_DURATION
+     */
+    CompositeData getSessionReadDuration();
+
+    /**
+     * @see org.apache.jackrabbit.api.stats.RepositoryStatistics.Type#SESSION_READ_AVERAGE
+     */
+    CompositeData getSessionReadAverage();
+
+    /**
+     * @see org.apache.jackrabbit.api.stats.RepositoryStatistics.Type#SESSION_WRITE_COUNTER
+     */
+    CompositeData getSessionWriteCount();
+
+    /**
+     * @see org.apache.jackrabbit.api.stats.RepositoryStatistics.Type#SESSION_READ_DURATION
+     */
+    CompositeData getSessionWriteDuration();
+
+    /**
+     * @see org.apache.jackrabbit.api.stats.RepositoryStatistics.Type#SESSION_WRITE_AVERAGE
+     */
+    CompositeData getSessionWriteAverage();
+
+    /**
+     * @see org.apache.jackrabbit.api.stats.RepositoryStatistics.Type#QUERY_COUNT
+     */
+    CompositeData getQueryCount();
+
+    /**
+     * @see org.apache.jackrabbit.api.stats.RepositoryStatistics.Type#QUERY_DURATION
+     */
+    CompositeData getQueryDuration();
+
+    /**
+     * @see org.apache.jackrabbit.api.stats.RepositoryStatistics.Type#QUERY_AVERAGE
+     */
+    CompositeData getQueryAverage();
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/stats/RepositoryStats.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/stats/RepositoryStats.java?rev=1565276&r1=1565275&r2=1565276&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/stats/RepositoryStats.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/stats/RepositoryStats.java
Thu Feb  6 14:29:28 2014
@@ -20,8 +20,16 @@
 package org.apache.jackrabbit.oak.stats;
 
 import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type;
+import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.QUERY_COUNT;
+import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.QUERY_DURATION;
 import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.SESSION_COUNT;
 import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.SESSION_LOGIN_COUNTER;
+import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.SESSION_READ_AVERAGE;
+import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.SESSION_READ_COUNTER;
+import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.SESSION_READ_DURATION;
+import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.SESSION_WRITE_AVERAGE;
+import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.SESSION_WRITE_COUNTER;
+import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.SESSION_WRITE_DURATION;
 
 import javax.management.openmbean.ArrayType;
 import javax.management.openmbean.CompositeData;
@@ -56,6 +64,51 @@ public class RepositoryStats implements 
         return asCompositeData(SESSION_LOGIN_COUNTER);
     }
 
+    @Override
+    public CompositeData getSessionReadCount() {
+        return asCompositeData(SESSION_READ_COUNTER);
+    }
+
+    @Override
+    public CompositeData getSessionReadDuration() {
+        return asCompositeData(SESSION_READ_DURATION);
+    }
+
+    @Override
+    public CompositeData getSessionReadAverage() {
+        return asCompositeData(SESSION_READ_AVERAGE);
+    }
+
+    @Override
+    public CompositeData getSessionWriteCount() {
+        return asCompositeData(SESSION_WRITE_COUNTER);
+    }
+
+    @Override
+    public CompositeData getSessionWriteDuration() {
+        return asCompositeData(SESSION_WRITE_DURATION);
+    }
+
+    @Override
+    public CompositeData getSessionWriteAverage() {
+        return asCompositeData(SESSION_WRITE_AVERAGE);
+    }
+
+    @Override
+    public CompositeData getQueryCount() {
+        return asCompositeData(QUERY_COUNT);
+    }
+
+    @Override
+    public CompositeData getQueryDuration() {
+        return asCompositeData(QUERY_DURATION);
+    }
+
+    @Override
+    public CompositeData getQueryAverage() {
+        return asCompositeData(Type.QUERY_AVERAGE);
+    }
+
     public static final String[] ITEM_NAMES = new String[] {
             "per second", "per minute", "per hour", "per week"};
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java?rev=1565276&r1=1565275&r2=1565276&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java
Thu Feb  6 14:29:28 2014
@@ -17,10 +17,15 @@
 package org.apache.jackrabbit.oak.jcr.delegate;
 
 import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.SESSION_READ_COUNTER;
+import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.SESSION_READ_DURATION;
+import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.SESSION_WRITE_COUNTER;
+import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.SESSION_WRITE_DURATION;
 import static org.apache.jackrabbit.oak.commons.PathUtils.denotesRoot;
 
 import java.io.IOException;
 import java.util.Iterator;
+import java.util.concurrent.atomic.AtomicLong;
 
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
@@ -40,6 +45,7 @@ import org.apache.jackrabbit.oak.jcr.ses
 import org.apache.jackrabbit.oak.jcr.session.SessionStats;
 import org.apache.jackrabbit.oak.jcr.session.operation.SessionOperation;
 import org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager;
+import org.apache.jackrabbit.oak.stats.StatisticManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Marker;
@@ -59,6 +65,11 @@ public class SessionDelegate {
     private final IdentifierManager idManager;
     private final SessionStats sessionStats;
 
+    private final AtomicLong readCounter;
+    private final AtomicLong readDuration;
+    private final AtomicLong writeCounter;
+    private final AtomicLong writeDuration;
+
     private boolean isAlive = true;
     private int sessionOpCount;
     private long updateCount = 0;
@@ -75,13 +86,22 @@ public class SessionDelegate {
      *
      * @param contentSession  the content session
      * @param refreshStrategy  the refresh strategy used for auto refreshing this session
+     * @param statisticManager the statistics manager for tracking session operations
      */
-    public SessionDelegate(@Nonnull ContentSession contentSession, RefreshStrategy refreshStrategy)
{
+    public SessionDelegate(
+            @Nonnull ContentSession contentSession,
+            @Nonnull RefreshStrategy refreshStrategy,
+            @Nonnull StatisticManager statisticManager) {
         this.contentSession = checkNotNull(contentSession);
         this.refreshStrategy = checkNotNull(refreshStrategy);
         this.root = contentSession.getLatestRoot();
         this.idManager = new IdentifierManager(root);
         this.sessionStats = new SessionStats(this);
+        checkNotNull(statisticManager);
+        readCounter = statisticManager.getCounter(SESSION_READ_COUNTER);
+        readDuration = statisticManager.getCounter(SESSION_READ_DURATION);
+        writeCounter = statisticManager.getCounter(SESSION_WRITE_COUNTER);
+        writeDuration = statisticManager.getCounter(SESSION_WRITE_DURATION);
     }
 
     @Nonnull
@@ -128,18 +148,24 @@ public class SessionDelegate {
             }
             sessionOperation.checkPreconditions();
         }
+        long t0 = System.nanoTime();
         try {
             sessionOpCount++;
             T result =  sessionOperation.perform();
             logOperationDetails(sessionOperation);
             return result;
         } finally {
+            long dt = System.nanoTime() - t0;
             sessionOpCount--;
             if (sessionOperation.isUpdate()) {
                 sessionStats.write();
+                writeCounter.incrementAndGet();
+                writeDuration.addAndGet(dt);
                 updateCount++;
             } else {
                 sessionStats.read();
+                readCounter.incrementAndGet();
+                readDuration.addAndGet(dt);
             }
             if (sessionOperation.isSave()) {
                 refreshStrategy.saved();

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/repository/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/repository/RepositoryImpl.java?rev=1565276&r1=1565275&r2=1565276&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/repository/RepositoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/repository/RepositoryImpl.java
Thu Feb  6 14:29:28 2014
@@ -235,7 +235,7 @@ public class RepositoryImpl implements J
     private SessionDelegate createSessionDelegate(
             final RefreshStrategy refreshStrategy,
             final ContentSession contentSession) {
-        return new SessionDelegate(contentSession, refreshStrategy) {
+        return new SessionDelegate(contentSession, refreshStrategy, statisticManager) {
             // Defer session MBean registration to avoid cluttering the
             // JMX name space with short lived sessions
             ListenableScheduledFuture<Registration> registration = scheduledExecutor.schedule(



Mime
View raw message