incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [1/2] git commit: populated the cpu times on the status object
Date Thu, 06 Jun 2013 02:55:46 GMT
Updated Branches:
  refs/heads/0.1.5 bf1258f8c -> 35954c2d2


populated the cpu times on the status object

Signed-off-by: Aaron McCurry <amccurry@gmail.com>


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

Branch: refs/heads/0.1.5
Commit: 19494352dc6548beae0c4c47e6f44f09f56a4d17
Parents: bf1258f
Author: Rahul Challapalli <challapallirahul@gmail.com>
Authored: Tue Jun 4 23:36:54 2013 -0700
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Wed Jun 5 22:54:50 2013 -0400

----------------------------------------------------------------------
 .../java/org/apache/blur/manager/IndexManager.java |    6 +-
 .../apache/blur/manager/status/QueryStatus.java    |   30 ++++++++++-----
 2 files changed, 23 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/19494352/src/blur-core/src/main/java/org/apache/blur/manager/IndexManager.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/main/java/org/apache/blur/manager/IndexManager.java b/src/blur-core/src/main/java/org/apache/blur/manager/IndexManager.java
index e7e3857..ea1d258 100644
--- a/src/blur-core/src/main/java/org/apache/blur/manager/IndexManager.java
+++ b/src/blur-core/src/main/java/org/apache/blur/manager/IndexManager.java
@@ -998,11 +998,11 @@ public class IndexManager {
 
     @Override
     public BlurResultIterable call(Entry<String, BlurIndex> entry) throws Exception
{
-      _status.attachThread();
+      String shard = entry.getKey();
+      _status.attachThread(shard);
       BlurIndex index = entry.getValue();
       IndexSearcherClosable searcher = index.getIndexReader();
       try {
-        String shard = entry.getKey();
         // @TODO need to add escapable rewriter
         // IndexReader escapeReader = EscapeRewrite.wrap(reader, _running);
         // IndexSearcher searcher = new IndexSearcher(escapeReader);
@@ -1018,7 +1018,7 @@ public class IndexManager {
             _shardServerContext == null);
       } finally {
         _queriesInternalMeter.mark();
-        _status.deattachThread();
+        _status.deattachThread(shard);
       }
     }
   }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/19494352/src/blur-core/src/main/java/org/apache/blur/manager/status/QueryStatus.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/main/java/org/apache/blur/manager/status/QueryStatus.java b/src/blur-core/src/main/java/org/apache/blur/manager/status/QueryStatus.java
index f1fe931..35895bb 100644
--- a/src/blur-core/src/main/java/org/apache/blur/manager/status/QueryStatus.java
+++ b/src/blur-core/src/main/java/org/apache/blur/manager/status/QueryStatus.java
@@ -21,12 +21,19 @@ import java.lang.management.ThreadMXBean;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicLong;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.blur.thrift.generated.BlurQuery;
 import org.apache.blur.thrift.generated.BlurQueryStatus;
 import org.apache.blur.thrift.generated.QueryState;
+import org.apache.blur.thrift.generated.CpuTime;
 
-
+/**
+ * This class is accessed by multiple threads (one for each shard) 
+ * executing the query. Tracks status and collects metrics
+ *
+ */
 public class QueryStatus implements Comparable<QueryStatus> {
 
   private final static boolean CPU_TIME_SUPPORTED = ManagementFactory.getThreadMXBean().isCurrentThreadCpuTimeSupported();
@@ -36,14 +43,13 @@ public class QueryStatus implements Comparable<QueryStatus> {
   private final long _startingTime;
   private boolean _finished = false;
   private long _finishedTime;
-  private final AtomicLong _cpuTimeOfFinishedThreads = new AtomicLong();
   private final ThreadMXBean _bean = ManagementFactory.getThreadMXBean();
   private final long _ttl;
-  private final ThreadLocal<Long> _cpuTimes = new ThreadLocal<Long>();
   private final AtomicBoolean _interrupted = new AtomicBoolean(false);
   private final AtomicInteger _totalShards = new AtomicInteger();
   private final AtomicInteger _completeShards = new AtomicInteger();
   private AtomicBoolean _running;
+  private final Map<String, CpuTime> _cpuTimes = new HashMap<String, CpuTime>();
 
   public QueryStatus(long ttl, String table, BlurQuery blurQuery, AtomicBoolean running)
{
     _ttl = ttl;
@@ -53,23 +59,26 @@ public class QueryStatus implements Comparable<QueryStatus> {
     _running = running;
   }
 
-  public QueryStatus attachThread() {
+  public QueryStatus attachThread(String shardName) {
+    CpuTime cpuTime = new CpuTime();
     if (CPU_TIME_SUPPORTED) {
-      _cpuTimes.set(_bean.getCurrentThreadCpuTime());
+      cpuTime.cpuTime = _bean.getCurrentThreadCpuTime();
     } else {
-      _cpuTimes.set(-1L);
+      cpuTime.cpuTime = -1L;
     }
+    cpuTime.realTime = System.nanoTime();
+    _cpuTimes.put(shardName, cpuTime);
     _totalShards.incrementAndGet();
     return this;
   }
 
-  public QueryStatus deattachThread() {
+  public QueryStatus deattachThread(String shardName) {
     _completeShards.incrementAndGet();
+     CpuTime cpuTime = _cpuTimes.get(shardName);
     if (CPU_TIME_SUPPORTED) {
-      long startingThreadCpuTime = _cpuTimes.get();
-      long currentThreadCpuTime = _bean.getCurrentThreadCpuTime();
-      _cpuTimeOfFinishedThreads.addAndGet(currentThreadCpuTime - startingThreadCpuTime);
+    	cpuTime.cpuTime = _bean.getCurrentThreadCpuTime() - cpuTime.cpuTime;
     }
+    cpuTime.realTime = System.nanoTime() - cpuTime.realTime;
     return this;
   }
 
@@ -91,6 +100,7 @@ public class QueryStatus implements Comparable<QueryStatus> {
     if (queryStatus.query != null) {
       queryStatus.uuid = queryStatus.query.uuid;
     }
+    queryStatus.cpuTimes = _cpuTimes;
     return queryStatus;
   }
 


Mime
View raw message