keith-turner commented on a change in pull request #1187: Log busy tablets by 
ingest and query at a configurable time duration
URL: https://github.com/apache/accumulo/pull/1187#discussion_r292053660
 
 

 ##########
 File path: 
server/tserver/src/main/java/org/apache/accumulo/tserver/TabletServer.java
 ##########
 @@ -358,6 +364,77 @@ public TabletServer(ServerConfigurationFactory 
confFactory, VolumeManager fs) th
     this.logSorter = new LogSorter(instance, fs, aconf);
     this.replWorker = new ReplicationWorker(this, fs);
     this.statsKeeper = new TabletStatsKeeper();
+    final int numBusyTabletsToLog = 
aconf.getCount(Property.TSERV_LOG_BUSY_TABLETS_COUNT);
+    final long logBusyTabletsDelay =
+        aconf.getTimeInMillis(Property.TSERV_LOG_BUSY_TABLETS_INTERVAL);
+
+    // This thread will calculate and log out the busiest tablets based on 
ingest count and
+    // query count every #{logBusiestTabletsDelay}
+    if (numBusyTabletsToLog > 0) {
+      SimpleTimer.getInstance(aconf).schedule(new Runnable() {
+        @Override
+        public void run() {
+          Comparator<Pair<String,Double>> busiestTabletComparator =
+              new Comparator<Pair<String,Double>>() {
+                @Override
+                public int compare(Pair<String,Double> first, 
Pair<String,Double> second) {
+                  return second.getSecond().compareTo(first.getSecond());
+                }
+              };
+          Map<String,PriorityQueue<Pair<String,Double>>> busyTabletMap = new 
HashMap<>();
+          busyTabletMap.put(INGEST_COUNT,
+              new PriorityQueue<>(numBusyTabletsToLog, 
busiestTabletComparator));
+          busyTabletMap.put(INGEST_RATE,
+              new PriorityQueue<>(numBusyTabletsToLog, 
busiestTabletComparator));
+          busyTabletMap.put(QUERY_COUNT,
+              new PriorityQueue<>(numBusyTabletsToLog, 
busiestTabletComparator));
+          busyTabletMap.put(QUERY_RATE,
+              new PriorityQueue<>(numBusyTabletsToLog, 
busiestTabletComparator));
+          List<Tablet> tablets;
+          synchronized (onlineTablets) {
+            tablets = new ArrayList<>(onlineTablets.values());
+          }
+          for (Tablet tablet : tablets) {
+            String extentString = tablet.getExtent().toString();
+            addToBusiestTablets(extentString, tablet.totalQueries(), 
busyTabletMap.get(QUERY_COUNT),
+                numBusyTabletsToLog);
+            addToBusiestTablets(extentString, tablet.queryRate(), 
busyTabletMap.get(QUERY_RATE),
+                numBusyTabletsToLog);
+            addToBusiestTablets(extentString, tablet.totalIngest(), 
busyTabletMap.get(INGEST_COUNT),
+                numBusyTabletsToLog);
+            addToBusiestTablets(extentString, tablet.ingestRate(), 
busyTabletMap.get(INGEST_RATE),
+                numBusyTabletsToLog);
+          }
+
+          logBusyTablets(busyTabletMap, QUERY_COUNT, numBusyTabletsToLog);
+          logBusyTablets(busyTabletMap, QUERY_RATE, numBusyTabletsToLog);
+          logBusyTablets(busyTabletMap, INGEST_COUNT, numBusyTabletsToLog);
+          logBusyTablets(busyTabletMap, INGEST_RATE, numBusyTabletsToLog);
+        }
+
+        private void addToBusiestTablets(String extent, double count,
+            PriorityQueue<Pair<String,Double>> busiestTabletsQueue, int 
numBusiestTabletsToLog) {
+          if (busiestTabletsQueue.size() < numBusiestTabletsToLog
+              || busiestTabletsQueue.peek().getSecond() < count) {
+            if (busiestTabletsQueue.size() == numBusiestTabletsToLog) {
+              busiestTabletsQueue.remove();
+            }
+            busiestTabletsQueue.add(new Pair<String,Double>(extent, count));
+          }
+        }
+
+        private void 
logBusyTablets(Map<String,PriorityQueue<Pair<String,Double>>> busyTabletsMap,
+            String label, int numBusiestTabletsToLog) {
+          PriorityQueue<Pair<String,Double>> busyTabletsQueue = 
busyTabletsMap.get(label);
+          for (int i = 0; i < numBusiestTabletsToLog; i++) {
 
 Review comment:
   I think the expectation is that this code empties the queue.  If it did not 
empty the queue for some reason it could lead to odd situations like the same 
tablet being on the queue multiple times.  To make this expectation more clear 
and to decouple this code from how the queue is created, could do the following 
instead of the for loop.
   
   ```java
   int i = 0;
   while(!busyTabletsQueue.isEmpty()) {
     Pair<String,Double> pair = busyTabletsQueue.poll();
     log.debug("{} busiest tablet by {} -- extent: {} count: {}", i++, label, 
pair.getFirst(),
                    pair.getSecond());
   }
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to