jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r831865 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene: IOCounters.java QueryResultImpl.java directory/FSDirectoryManager.java
Date Mon, 02 Nov 2009 11:14:26 GMT
Author: mreutegg
Date: Mon Nov  2 11:14:25 2009
New Revision: 831865

URL: http://svn.apache.org/viewvc?rev=831865&view=rev
Log:
JCR-2376: Add basic I/O counters to query handler

Added:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IOCounters.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/directory/FSDirectoryManager.java

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IOCounters.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IOCounters.java?rev=831865&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IOCounters.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IOCounters.java
Mon Nov  2 11:14:25 2009
@@ -0,0 +1,52 @@
+/*
+ * 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.query.lucene;
+
+/**
+ * <code>IOCounters</code> provides a basic mechanism to track I/O during query
+ * execution.
+ */
+public class IOCounters {
+
+    /**
+     * The key in the per-query-cache that identifies the read count.
+     */
+    private static final Object READ_COUNT = new Object();
+
+    /**
+     * @return the current read count for caused by the current thread.
+     */
+    public static long getReads() {
+        Long value = (Long) PerQueryCache.getInstance().get(IOCounters.class,  READ_COUNT);
+        if (value == null) {
+            value = 0L;
+        }
+        return value;
+    }
+
+    /**
+     * Increments the read count caused by the current thread.
+     */
+    public static void incrRead() {
+        PerQueryCache cache = PerQueryCache.getInstance();
+        Long value = (Long) cache.get(IOCounters.class,  READ_COUNT);
+        if (value == null) {
+            value = 0L;
+        }
+        cache.put(IOCounters.class, READ_COUNT, value + 1);
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IOCounters.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java?rev=831865&r1=831864&r2=831865&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java
Mon Nov  2 11:14:25 2009
@@ -290,9 +290,11 @@
         MultiColumnQueryHits result = null;
         try {
             long time = System.currentTimeMillis();
+            long r1 = IOCounters.getReads();
             result = executeQuery(maxResultSize);
-            log.debug("query executed in {} ms",
-                    System.currentTimeMillis() - time);
+            long r2 = IOCounters.getReads();
+            log.debug("query executed in {} ms ({})",
+                    System.currentTimeMillis() - time, r2 - r1);
             // set selector names
             selectorNames = result.getSelectorNames();
 
@@ -306,8 +308,9 @@
 
             time = System.currentTimeMillis();
             collectScoreNodes(result, resultNodes, maxResultSize);
-            log.debug("retrieved ScoreNodes in {} ms",
-                    System.currentTimeMillis() - time);
+            long r3 = IOCounters.getReads();
+            log.debug("retrieved ScoreNodes in {} ms ({})",
+                    System.currentTimeMillis() - time, r3 - r2);
 
             // update numResults
             numResults = result.getSize();

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/directory/FSDirectoryManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/directory/FSDirectoryManager.java?rev=831865&r1=831864&r2=831865&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/directory/FSDirectoryManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/directory/FSDirectoryManager.java
Mon Nov  2 11:14:25 2009
@@ -16,18 +16,19 @@
  */
 package org.apache.jackrabbit.core.query.lucene.directory;
 
+import java.io.File;
+import java.io.FileFilter;
+import java.io.IOException;
+
+import org.apache.jackrabbit.core.query.lucene.IOCounters;
+import org.apache.jackrabbit.core.query.lucene.SearchIndex;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.FSDirectory;
-import org.apache.lucene.store.NativeFSLockFactory;
-import org.apache.lucene.store.IndexOutput;
 import org.apache.lucene.store.IndexInput;
+import org.apache.lucene.store.IndexOutput;
 import org.apache.lucene.store.Lock;
 import org.apache.lucene.store.LockFactory;
-import org.apache.jackrabbit.core.query.lucene.SearchIndex;
-
-import java.io.IOException;
-import java.io.File;
-import java.io.FileFilter;
+import org.apache.lucene.store.NativeFSLockFactory;
 
 /**
  * <code>FSDirectoryManager</code> implements a directory manager for
@@ -185,7 +186,8 @@
         }
 
         public IndexInput openInput(String name) throws IOException {
-            return directory.openInput(name);
+            IndexInput in = directory.openInput(name);
+            return new IndexInputLogWrapper(in);
         }
 
         public void close() throws IOException {
@@ -194,7 +196,8 @@
 
         public IndexInput openInput(String name, int bufferSize)
                 throws IOException {
-            return directory.openInput(name, bufferSize);
+            IndexInput in = directory.openInput(name, bufferSize);
+            return new IndexInputLogWrapper(in);
         }
 
         public Lock makeLock(String name) {
@@ -221,4 +224,49 @@
             return this.getClass().getName() + "@" + directory;
         }
     }
+
+    /**
+     * Implements an index input wrapper that logs the number of time bytes
+     * are read from storage.
+     */
+    private static final class IndexInputLogWrapper extends IndexInput {
+
+        private IndexInput in;
+
+        IndexInputLogWrapper(IndexInput in) {
+            this.in = in;
+        }
+
+        public byte readByte() throws IOException {
+            return in.readByte();
+        }
+
+        public void readBytes(byte[] b, int offset, int len) throws IOException {
+            IOCounters.incrRead();
+            in.readBytes(b, offset, len);
+        }
+
+        public void close() throws IOException {
+            in.close();
+        }
+
+        public long getFilePointer() {
+            return in.getFilePointer();
+        }
+
+        public void seek(long pos) throws IOException {
+            in.seek(pos);
+        }
+
+        public long length() {
+            return in.length();
+        }
+
+        @Override
+        public Object clone() {
+            IndexInputLogWrapper clone = (IndexInputLogWrapper) super.clone();
+            clone.in = (IndexInput) in.clone();
+            return clone;
+        }
+    }
 }



Mime
View raw message