jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1160248 - in /jackrabbit/branches/JCR-2936: jackrabbit-api/src/main/java/org/apache/jackrabbit/api/jmx/ jackrabbit-api/src/main/java/org/apache/jackrabbit/api/management/ jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/ jackra...
Date Mon, 22 Aug 2011 12:58:51 GMT
Author: alexparvulescu
Date: Mon Aug 22 12:58:50 2011
New Revision: 1160248

URL: http://svn.apache.org/viewvc?rev=1160248&view=rev
Log:
JCR-2936 JMX Bindings for Jackrabbit
 - stats: new branch, take 1

Added:
    jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/jmx/
    jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/jmx/CoreStatManagerMBean.java
  (with props)
    jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/jmx/ManagedRepositoryMBean.java
      - copied, changed from r1160221, jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/management/ManagedRepositoryMBean.java
    jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/jmx/QueryStatManagerMBean.java
  (with props)
    jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/
    jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/CoreStat.java
  (with props)
    jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/QueryStat.java
  (with props)
    jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/QueryStatDto.java
  (with props)
    jackrabbit/branches/JCR-2936/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/
    jackrabbit/branches/JCR-2936/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/AbstractStatTest.java
  (with props)
    jackrabbit/branches/JCR-2936/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/CoreStatSessionTest.java
  (with props)
    jackrabbit/branches/JCR-2936/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/QueryStatManagerTest.java
  (with props)
    jackrabbit/branches/JCR-2936/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/TestAll.java
  (with props)
    jackrabbit/branches/JCR-2936/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/util/
    jackrabbit/branches/JCR-2936/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/util/CachingOpsPerSecondDtoTest.java
  (with props)
Removed:
    jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/management/ManagedRepositoryMBean.java
Modified:
    jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryContext.java
    jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
    jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryImpl.java
    jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryObjectModelImpl.java
    jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java

Added: jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/jmx/CoreStatManagerMBean.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/jmx/CoreStatManagerMBean.java?rev=1160248&view=auto
==============================================================================
--- jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/jmx/CoreStatManagerMBean.java
(added)
+++ jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/jmx/CoreStatManagerMBean.java
Mon Aug 22 12:58:50 2011
@@ -0,0 +1,37 @@
+/*
+ * 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.api.jmx;
+
+/**
+ * The CoreStatManagerMBean exposes the CoreStat info via JMX
+ * 
+ */
+public interface CoreStatManagerMBean {
+
+    String NAME = "org.apache.jackrabbit:type=CoreStats";
+
+    long getNumberOfSessions();
+
+    void resetNumberOfSessions();
+
+    double getReadOpsPerSecond();
+
+    double getWriteOpsPerSecond();
+
+    void resetNumberOfOperations();
+
+}

Propchange: jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/jmx/CoreStatManagerMBean.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/jmx/ManagedRepositoryMBean.java
(from r1160221, jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/management/ManagedRepositoryMBean.java)
URL: http://svn.apache.org/viewvc/jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/jmx/ManagedRepositoryMBean.java?p2=jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/jmx/ManagedRepositoryMBean.java&p1=jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/management/ManagedRepositoryMBean.java&r1=1160221&r2=1160248&rev=1160248&view=diff
==============================================================================
--- jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/management/ManagedRepositoryMBean.java
(original)
+++ jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/jmx/ManagedRepositoryMBean.java
Mon Aug 22 12:58:50 2011
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.api.management;
+package org.apache.jackrabbit.api.jmx;
 
 import java.util.Map;
 

Added: jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/jmx/QueryStatManagerMBean.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/jmx/QueryStatManagerMBean.java?rev=1160248&view=auto
==============================================================================
--- jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/jmx/QueryStatManagerMBean.java
(added)
+++ jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/jmx/QueryStatManagerMBean.java
Mon Aug 22 12:58:50 2011
@@ -0,0 +1,50 @@
+/*
+ * 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.api.jmx;
+
+import javax.management.openmbean.TabularData;
+
+import org.apache.jackrabbit.api.stats.QueryStat;
+
+/**
+ * JMX Bindings for {@link QueryStat}.
+ * 
+ */
+public interface QueryStatManagerMBean {
+
+    String NAME = "org.apache.jackrabbit:type=QueryStats";
+
+    TabularData getQueries();
+
+    /**
+     * @return how big the <b>Top X</b> queue is
+     */
+    int getQueueSize();
+
+    /**
+     * Change the <b>Top X</b> queue size
+     * 
+     * @param size
+     *            the new size
+     */
+    void setQueueSize(int size);
+
+    /**
+     * clears the queue
+     */
+    void clearQueue();
+}

Propchange: jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/jmx/QueryStatManagerMBean.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/CoreStat.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/CoreStat.java?rev=1160248&view=auto
==============================================================================
--- jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/CoreStat.java
(added)
+++ jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/CoreStat.java
Mon Aug 22 12:58:50 2011
@@ -0,0 +1,66 @@
+/*
+ * 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.api.stats;
+
+/**
+ * Statistics on core JCR operations
+ * 
+ */
+public interface CoreStat {
+
+    /** -- SESSION INFO -- **/
+
+    void sessionCreated();
+
+    void sessionLoggedOut();
+
+    long getNumberOfSessions();
+
+    void resetNumberOfSessions();
+
+    /**
+     * @param timeNs
+     *            as given by timeNs = System.nanoTime() - timeNs;
+     */
+    void onSessionOperation(boolean isWrite, long timeNs);
+
+    double getReadOpsPerSecond();
+
+    double getWriteOpsPerSecond();
+
+    void resetNumberOfOperations();
+
+    /**
+     * If this service is currently registering stats
+     * 
+     * @return <code>true</code> if the service is enabled
+     */
+    boolean isEnabled();
+
+    /**
+     * Enables/Disables the service
+     * 
+     * @param enabled
+     */
+    void setEnabled(boolean enabled);
+
+    /**
+     * clears all data
+     */
+    void reset();
+
+}

Propchange: jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/CoreStat.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/QueryStat.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/QueryStat.java?rev=1160248&view=auto
==============================================================================
--- jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/QueryStat.java
(added)
+++ jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/QueryStat.java
Mon Aug 22 12:58:50 2011
@@ -0,0 +1,74 @@
+/*
+ * 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.api.stats;
+
+/**
+ * Statistics on query operations
+ * 
+ */
+public interface QueryStat {
+
+    void logQuery(final String language, final String statement, long duration);
+
+    /** Slowest Queries */
+
+    QueryStatDto[] getSlowQueries();
+
+    /**
+     * @return how big the <b>Top X</b> queue is
+     */
+    int getSlowQueriesQueueSize();
+
+    /**
+     * Change the <b>Top X</b> queue size
+     * 
+     * @param size
+     *            the new size
+     */
+    void setSlowQueriesQueueSize(int size);
+
+    /**
+     * clears the queue
+     */
+    void clearSlowQueriesQueue();
+
+    double getQueriesPerSecond();
+
+    double getAvgQueryTime();
+
+    /** Generic Stats Stuff */
+
+    /**
+     * If this service is currently registering stats
+     * 
+     * @return <code>true</code> if the service is enabled
+     */
+    boolean isEnabled();
+
+    /**
+     * Enables/Disables the service
+     * 
+     * @param enabled
+     */
+    void setEnabled(boolean enabled);
+
+    /**
+     * clears all data
+     */
+    void reset();
+
+}

Propchange: jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/QueryStat.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/QueryStatDto.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/QueryStatDto.java?rev=1160248&view=auto
==============================================================================
--- jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/QueryStatDto.java
(added)
+++ jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/QueryStatDto.java
Mon Aug 22 12:58:50 2011
@@ -0,0 +1,39 @@
+/*
+ * 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.api.stats;
+
+import java.io.Serializable;
+
+/**
+ * Object that holds statistical info about a query.
+ * 
+ */
+public interface QueryStatDto extends Serializable {
+
+    long getDuration();
+
+    String getLanguage();
+
+    String getStatement();
+
+    String getCreationTime();
+
+    long getPosition();
+
+    void setPosition(long position);
+
+}

Propchange: jackrabbit/branches/JCR-2936/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/QueryStatDto.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryContext.java?rev=1160248&r1=1160247&r2=1160248&view=diff
==============================================================================
--- jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryContext.java
(original)
+++ jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryContext.java
Mon Aug 22 12:58:50 2011
@@ -25,6 +25,7 @@ import org.apache.jackrabbit.core.nodety
 import org.apache.jackrabbit.core.security.JackrabbitSecurityManager;
 import org.apache.jackrabbit.core.security.authorization.PrivilegeRegistry;
 import org.apache.jackrabbit.core.state.ItemStateCacheFactory;
+import org.apache.jackrabbit.core.stats.StatManager;
 import org.apache.jackrabbit.core.version.InternalVersionManagerImpl;
 import org.apache.jackrabbit.util.Timer;
 
@@ -105,6 +106,11 @@ public class RepositoryContext {
     private final Timer timer = new Timer(false);
 
     /**
+     * The Statistics manager, handles statistics and jmx support
+     */
+    private StatManager statManager;
+
+    /**
      * Creates a component context for the given repository.
      *
      * @param repository repository instance
@@ -359,4 +365,13 @@ public class RepositoryContext {
         return nodeIdFactory;
     }
 
+    public StatManager getStatManager() {
+        assert statManager != null;
+        return statManager;
+    }
+
+    public void setStatManager(StatManager statManager) {
+        assert statManager != null;
+        this.statManager = statManager;
+    }
 }

Modified: jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java?rev=1160248&r1=1160247&r2=1160248&view=diff
==============================================================================
--- jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
(original)
+++ jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
Mon Aug 22 12:58:50 2011
@@ -105,6 +105,7 @@ import org.apache.jackrabbit.core.state.
 import org.apache.jackrabbit.core.state.ItemStateException;
 import org.apache.jackrabbit.core.state.ManagedMLRUItemStateCacheFactory;
 import org.apache.jackrabbit.core.state.SharedItemStateManager;
+import org.apache.jackrabbit.core.stats.StatManager;
 import org.apache.jackrabbit.core.util.RepositoryLockMechanism;
 import org.apache.jackrabbit.core.version.InternalVersionManager;
 import org.apache.jackrabbit.core.version.InternalVersionManagerImpl;
@@ -232,6 +233,11 @@ public class RepositoryImpl extends Abst
     private final CacheManager cacheMgr = new CacheManager();
 
     /**
+     * The Statistics manager, handles statistics and jmx support
+     */
+    private final StatManager statManager = new StatManager();
+
+    /**
      * Chanel for posting create workspace messages.
      */
     private WorkspaceEventChannel createWorkspaceEventChannel;
@@ -355,6 +361,9 @@ public class RepositoryImpl extends Abst
             // initialize system search manager
             getSystemSearchManager(repConfig.getDefaultWorkspaceName());
 
+            //this has to be live before initSecurityManager(), to be able to track all the
queries
+            initStatManager();
+
             // Initialise the security manager;
             initSecurityManager();
 
@@ -461,6 +470,10 @@ public class RepositoryImpl extends Abst
         return cacheMgr;
     }
 
+    public StatManager getStatManager() {
+        return statManager;
+    }
+
     /**
      * Creates the {@link org.apache.jackrabbit.core.security.JackrabbitSecurityManager SecurityManager}
      * of this <code>Repository</code> and adds it to the repository context.
@@ -1003,6 +1016,7 @@ public class RepositoryImpl extends Abst
             session.addListener(this);
             activeSessions.put(session, session);
         }
+        statManager.getCoreStat().sessionCreated();
     }
 
     /**
@@ -1192,6 +1206,8 @@ public class RepositoryImpl extends Abst
 
         context.getTimer().cancel();
 
+        statManager.stop();
+
         log.info("Repository has been shutdown");
     }
 
@@ -1452,6 +1468,11 @@ public class RepositoryImpl extends Abst
         return new GarbageCollector(context.getDataStore(), ipmList, sessions);
     }
 
+    protected void initStatManager() {
+        this.statManager.init();
+        this.context.setStatManager(statManager);
+    }
+
     //-----------------------------------------------------------< Repository >
     /**
      * {@inheritDoc}
@@ -1587,6 +1608,7 @@ public class RepositoryImpl extends Abst
             // remove session from active sessions
             activeSessions.remove(session);
         }
+        statManager.getCoreStat().sessionLoggedOut();
     }
 
     //------------------------------------------< overridable factory methods >

Modified: jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryImpl.java?rev=1160248&r1=1160247&r2=1160248&view=diff
==============================================================================
--- jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryImpl.java
(original)
+++ jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryImpl.java
Mon Aug 22 12:58:50 2011
@@ -20,8 +20,6 @@ import static org.apache.jackrabbit.spi.
 import static org.apache.jackrabbit.spi.commons.name.NameConstants.JCR_STATEMENT;
 import static org.apache.jackrabbit.spi.commons.name.NameConstants.NT_QUERY;
 
-import java.text.NumberFormat;
-
 import javax.jcr.ItemExistsException;
 import javax.jcr.ItemNotFoundException;
 import javax.jcr.Node;
@@ -35,6 +33,7 @@ import javax.jcr.query.InvalidQueryExcep
 import javax.jcr.query.QueryResult;
 import javax.jcr.version.VersionException;
 
+import org.apache.jackrabbit.api.stats.QueryStat;
 import org.apache.jackrabbit.core.session.SessionContext;
 import org.apache.jackrabbit.core.session.SessionOperation;
 import org.apache.jackrabbit.spi.Path;
@@ -135,14 +134,13 @@ public class QueryImpl extends AbstractQ
                         return "query.execute(" + statement + ")";
                     }
                 });
-        
-        if (log.isDebugEnabled()) {
+        final QueryStat queryStat = sessionContext.getRepositoryContext()
+                .getStatManager().getQueryStat();
+        if (queryStat.isEnabled() || log.isDebugEnabled()) {
             time = System.currentTimeMillis() - time;
-            NumberFormat format = NumberFormat.getNumberInstance();
-            format.setMinimumFractionDigits(2);
-            format.setMaximumFractionDigits(2);
-            String seconds = format.format((double) time / 1000);
-            log.debug("executed in " + seconds + " s. (" + statement + ")");
+            sessionContext.getRepositoryContext().getStatManager()
+                    .getQueryStat().logQuery(language, statement, time);
+            log.debug("executed in {} ms. ({})", time, statement);
         }
         return result;
     }

Modified: jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryObjectModelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryObjectModelImpl.java?rev=1160248&r1=1160247&r2=1160248&view=diff
==============================================================================
--- jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryObjectModelImpl.java
(original)
+++ jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryObjectModelImpl.java
Mon Aug 22 12:58:50 2011
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.core.query;
 
-import java.text.NumberFormat;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -31,6 +30,7 @@ import javax.jcr.query.qom.Ordering;
 import javax.jcr.query.qom.QueryObjectModel;
 import javax.jcr.query.qom.Source;
 
+import org.apache.jackrabbit.api.stats.QueryStat;
 import org.apache.jackrabbit.commons.query.QueryObjectModelBuilderRegistry;
 import org.apache.jackrabbit.core.query.lucene.LuceneQueryFactory;
 import org.apache.jackrabbit.core.query.lucene.SearchIndex;
@@ -122,13 +122,12 @@ public class QueryObjectModelImpl extend
         long time = System.currentTimeMillis();
         QueryResult qr = engine.execute(getColumns(), getSource(),
                 getConstraint(), getOrderings(), offset, limit);
-        if (log.isDebugEnabled()) {
+        final QueryStat queryStat = sessionContext.getRepositoryContext()
+                .getStatManager().getQueryStat();
+        if (queryStat.isEnabled() || log.isDebugEnabled()) {
             time = System.currentTimeMillis() - time;
-            NumberFormat format = NumberFormat.getNumberInstance();
-            format.setMinimumFractionDigits(2);
-            format.setMaximumFractionDigits(2);
-            String seconds = format.format((double) time / 1000);
-            log.debug("executed in " + seconds + " s. (" + statement + ")");
+            queryStat.logQuery(language, statement, time);
+            log.debug("executed in {} ms. ({})", time, statement);
         }
         return qr;
     }

Modified: jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java?rev=1160248&r1=1160247&r2=1160248&view=diff
==============================================================================
--- jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java
(original)
+++ jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java
Mon Aug 22 12:58:50 2011
@@ -22,6 +22,7 @@ import java.util.concurrent.locks.Reentr
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 
+import org.apache.jackrabbit.api.stats.CoreStat;
 import org.apache.jackrabbit.core.WorkspaceManager;
 import org.apache.jackrabbit.core.observation.ObservationDispatcher;
 import org.slf4j.Logger;
@@ -180,14 +181,16 @@ public class SessionState {
             }
 
             try {
+                final CoreStat coreStat = context.getRepositoryContext().getStatManager().getCoreStat();
                 // Perform the actual operation, optionally with debug logs
-                if (log.isDebugEnabled()) {
+                if (log.isDebugEnabled() || coreStat.isEnabled()) {
                     log.debug("Performing {}", operation);
                     long start = System.nanoTime();
                     try {
                         return operation.perform(context);
                     } finally {
                         long time = System.nanoTime() - start;
+                        coreStat.onSessionOperation(isWriteOperation, time);
                         if (time > NS_PER_MS) {
                             log.debug("Performed {} in {}ms",
                                     operation, time / NS_PER_MS);

Added: jackrabbit/branches/JCR-2936/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/AbstractStatTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/JCR-2936/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/AbstractStatTest.java?rev=1160248&view=auto
==============================================================================
--- jackrabbit/branches/JCR-2936/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/AbstractStatTest.java
(added)
+++ jackrabbit/branches/JCR-2936/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/AbstractStatTest.java
Mon Aug 22 12:58:50 2011
@@ -0,0 +1,34 @@
+/*
+ * 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.core.stats;
+
+import org.apache.jackrabbit.core.RepositoryImpl;
+import org.apache.jackrabbit.test.AbstractJCRTest;
+
+/**
+ * Used as a base class for Statistics related tests.
+ */
+public abstract class AbstractStatTest extends AbstractJCRTest {
+
+    protected StatManager statManager;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        RepositoryImpl r = (RepositoryImpl) superuser.getRepository();
+        statManager = r.getStatManager();
+    }
+}

Propchange: jackrabbit/branches/JCR-2936/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/AbstractStatTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jackrabbit/branches/JCR-2936/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/CoreStatSessionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/JCR-2936/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/CoreStatSessionTest.java?rev=1160248&view=auto
==============================================================================
--- jackrabbit/branches/JCR-2936/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/CoreStatSessionTest.java
(added)
+++ jackrabbit/branches/JCR-2936/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/CoreStatSessionTest.java
Mon Aug 22 12:58:50 2011
@@ -0,0 +1,83 @@
+/*
+ * 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.core.stats;
+
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+
+import org.apache.jackrabbit.api.stats.CoreStat;
+
+/**
+ * CoreStats tests.
+ */
+public class CoreStatSessionTest extends AbstractStatTest {
+
+    // TODO add test for number of operations executed
+
+    private CoreStat cs;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        cs = statManager.getCoreStat();
+        cs.resetNumberOfSessions();
+    }
+
+    public void testNumberOfSessions1() throws Exception {
+
+        cs.setEnabled(true);
+        assertEquals(0, cs.getNumberOfSessions());
+
+        Session s = superuser.impersonate(new SimpleCredentials("anonymous", ""
+                .toCharArray()));
+        assertNotNull(s);
+        assertEquals(1, cs.getNumberOfSessions());
+
+        s.logout();
+        assertEquals(0, cs.getNumberOfSessions());
+    }
+
+    public void testNumberOfSessions2() throws Exception {
+
+        cs.setEnabled(false);
+        assertEquals(0, cs.getNumberOfSessions());
+
+        Session s = superuser.impersonate(new SimpleCredentials("anonymous", ""
+                .toCharArray()));
+        assertNotNull(s);
+        assertEquals(0, cs.getNumberOfSessions());
+
+        s.logout();
+        assertEquals(0, cs.getNumberOfSessions());
+    }
+
+    public void testNumberOfSessions3() throws Exception {
+
+        cs.setEnabled(true);
+        assertEquals(0, cs.getNumberOfSessions());
+
+        Session s = superuser.impersonate(new SimpleCredentials("anonymous", ""
+                .toCharArray()));
+        assertNotNull(s);
+        assertEquals(1, cs.getNumberOfSessions());
+
+        cs.resetNumberOfSessions();
+        assertEquals(0, cs.getNumberOfSessions());
+
+        s.logout();
+        assertEquals(0, cs.getNumberOfSessions());
+    }
+}

Propchange: jackrabbit/branches/JCR-2936/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/CoreStatSessionTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jackrabbit/branches/JCR-2936/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/QueryStatManagerTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/JCR-2936/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/QueryStatManagerTest.java?rev=1160248&view=auto
==============================================================================
--- jackrabbit/branches/JCR-2936/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/QueryStatManagerTest.java
(added)
+++ jackrabbit/branches/JCR-2936/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/QueryStatManagerTest.java
Mon Aug 22 12:58:50 2011
@@ -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.core.stats;
+
+import javax.jcr.query.Query;
+
+import org.apache.jackrabbit.api.stats.QueryStat;
+import org.apache.jackrabbit.api.stats.QueryStatDto;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * QueryStat tests.
+ */
+public class QueryStatManagerTest extends AbstractStatTest {
+
+    private static Logger log = LoggerFactory
+            .getLogger(QueryStatManagerTest.class);
+
+    private QueryStat qs;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        qs = statManager.getQueryStat();
+        qs.reset();
+    }
+
+    public void testLogDuration() throws Exception {
+        int queueSize = 15;
+        int runTimes = 50;
+
+        qs.setSlowQueriesQueueSize(queueSize);
+        qs.setEnabled(false);
+
+        // just to warm up the cache
+        double initial = doStatTest(runTimes);
+
+        qs.setEnabled(false);
+        double off = doStatTest(runTimes);
+
+        qs.setEnabled(true);
+        double on = doStatTest(runTimes);
+
+        log.info("Logging times: initial=" + initial
+                + ", without QueryStatManager = " + off
+                + ", with QueryStatManager = " + on);
+
+        QueryStatDto[] top = qs.getSlowQueries();
+        assertNotNull("Query Top should not be null", top);
+        assertEquals("Query Top should contain entries ",
+                Math.min(queueSize, runTimes), top.length);
+    }
+
+    private double doStatTest(int times) throws Exception {
+
+        long total = 0;
+        for (int i = 0; i < times; i++) {
+            long start = System.currentTimeMillis();
+            Query q = superuser.getWorkspace().getQueryManager()
+                    .createQuery("SELECT * FROM [nt:base]", Query.JCR_SQL2);
+            q.execute();
+            long dur = System.currentTimeMillis() - start;
+            total += dur;
+        }
+        return (double) total / times;
+    }
+}

Propchange: jackrabbit/branches/JCR-2936/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/QueryStatManagerTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jackrabbit/branches/JCR-2936/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/JCR-2936/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/TestAll.java?rev=1160248&view=auto
==============================================================================
--- jackrabbit/branches/JCR-2936/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/TestAll.java
(added)
+++ jackrabbit/branches/JCR-2936/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/TestAll.java
Mon Aug 22 12:58:50 2011
@@ -0,0 +1,44 @@
+/*
+ * 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.core.stats;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.jackrabbit.core.stats.util.CachingOpsPerSecondDtoTest;
+
+/**
+ * TestSuite for all Stats tests.
+ */
+public class TestAll extends TestCase {
+
+    /**
+     * Returns a <code>Test</code> suite that executes all tests inside this
+     * package.
+     * 
+     */
+    public static Test suite() {
+        TestSuite suite = new TestSuite();
+
+        suite.addTestSuite(CoreStatSessionTest.class);
+        suite.addTestSuite(QueryStatManagerTest.class);
+        suite.addTestSuite(CachingOpsPerSecondDtoTest.class);
+
+        return suite;
+    }
+}

Propchange: jackrabbit/branches/JCR-2936/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/TestAll.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jackrabbit/branches/JCR-2936/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/util/CachingOpsPerSecondDtoTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/JCR-2936/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/util/CachingOpsPerSecondDtoTest.java?rev=1160248&view=auto
==============================================================================
--- jackrabbit/branches/JCR-2936/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/util/CachingOpsPerSecondDtoTest.java
(added)
+++ jackrabbit/branches/JCR-2936/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/util/CachingOpsPerSecondDtoTest.java
Mon Aug 22 12:58:50 2011
@@ -0,0 +1,135 @@
+/*
+ * 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.core.stats.util;
+
+import java.math.BigDecimal;
+import java.math.MathContext;
+import java.math.RoundingMode;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.jackrabbit.test.JUnitTest;
+
+public class CachingOpsPerSecondDtoTest extends JUnitTest {
+
+    private final CachingOpsPerSecondDto test = new CachingOpsPerSecondDto(
+            1000 * 10000);
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        test.reset();
+    }
+
+    public void testSimple() throws Exception {
+
+        long t = System.currentTimeMillis();
+        test.reset();
+        test.onOp(10);
+        test.onOp(1);
+        TimeUnit.MILLISECONDS.sleep(1300);
+        test.onOp(2);
+        long d_min = System.currentTimeMillis() - t;
+        test.refresh();
+        long d_max = System.currentTimeMillis() - t;
+
+        // 3 ops in ~ 1.3 seconds = 2.3 ops / sec
+        double expected_min = BigDecimal.valueOf(3 * 1000)
+                .divide(BigDecimal.valueOf(d_min), new MathContext(3))
+                .round(new MathContext(2, RoundingMode.DOWN)).doubleValue();
+        double expected_max = BigDecimal.valueOf(3 * 1000)
+                .divide(BigDecimal.valueOf(d_max), new MathContext(3))
+                .add(new BigDecimal(0.001))
+                .round(new MathContext(2, RoundingMode.UP)).doubleValue();
+        double opsPerSecond = test.getOpsPerSecond();
+
+        assertTrue(opsPerSecond + "?" + expected_min,
+                opsPerSecond >= expected_min);
+        assertTrue(opsPerSecond + "?" + expected_max,
+                opsPerSecond <= expected_max);
+        assertEquals(4.33, test.getOpAvgTime());
+
+    }
+
+    public void testMT() throws Exception {
+        int threads = 20;
+        int ops = 60 * threads;
+
+        final Random r = new Random();
+        test.reset();
+        long t = System.currentTimeMillis();
+        int aggDuration = 0;
+        ExecutorService executor = Executors.newFixedThreadPool(threads);
+        List<Future<Void>> futures = new ArrayList<Future<Void>>();
+        for (int i = 0; i < ops; i++) {
+            int duration = 35 + r.nextInt(10);
+            boolean shouldRefresh = i % 10 == 0;
+            futures.add(executor.submit(newCallable(test, duration, 75,
+                    shouldRefresh)));
+            aggDuration += duration;
+        }
+        executor.shutdown();
+        for (Future<Void> f : futures) {
+            f.get();
+        }
+
+        long d_min = System.currentTimeMillis() - t;
+        test.refresh();
+        long d_max = System.currentTimeMillis() - t;
+
+        double expected_min = BigDecimal.valueOf(ops * 1000)
+                .divide(BigDecimal.valueOf(d_min), new MathContext(3))
+                .round(new MathContext(2, RoundingMode.DOWN)).doubleValue();
+        double expected_max = BigDecimal.valueOf(ops * 1000)
+                .divide(BigDecimal.valueOf(d_max), new MathContext(3))
+                .add(new BigDecimal(0.001))
+                .round(new MathContext(2, RoundingMode.UP)).doubleValue();
+        double opsPerSecond = test.getOpsPerSecond();
+
+        assertTrue(opsPerSecond + "?" + expected_min,
+                opsPerSecond >= expected_min);
+        assertTrue(opsPerSecond + "?" + expected_max,
+                opsPerSecond <= expected_max);
+
+        double expectedAvg = BigDecimal
+                .valueOf(aggDuration)
+                .divide(BigDecimal.valueOf(ops),
+                        new MathContext(2, RoundingMode.DOWN)).doubleValue();
+        assertEquals(expectedAvg, BigDecimal.valueOf(test.getOpAvgTime())
+                .round(new MathContext(2, RoundingMode.DOWN)).doubleValue());
+    }
+
+    private Callable<Void> newCallable(final CachingOpsPerSecondDto test,
+            final int duration, final long sleep, final boolean shouldRefresh) {
+        return new Callable<Void>() {
+
+            public Void call() throws Exception {
+                test.onOp(duration);
+                TimeUnit.MILLISECONDS.sleep(sleep);
+                if (shouldRefresh) {
+                    test.refresh();
+                }
+                return null;
+            }
+        };
+    }
+}

Propchange: jackrabbit/branches/JCR-2936/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/util/CachingOpsPerSecondDtoTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message