ctubbsii commented on a change in pull request #2283:
URL: https://github.com/apache/accumulo/pull/2283#discussion_r714964100
##########
File path: server/monitor/src/main/java/org/apache/accumulo/monitor/Monitor.java
##########
@@ -553,7 +565,24 @@ private ServletHolder getRestServlet() {
}
}
+ public static class CompactionStats {
+ public final long count;
+ public final Long oldest;
+ public final long fetched;
+
+ CompactionStats(List<ActiveCompaction> active) {
+ this.count = active.size();
+ long oldest = -1;
+ for (ActiveCompaction a : active) {
+ oldest = Math.max(oldest, a.age);
+ }
+ this.oldest = oldest < 0 ? null : oldest;
+ this.fetched = System.currentTimeMillis();
Review comment:
This should use nano time to compute time durations.
##########
File path: server/monitor/src/main/java/org/apache/accumulo/monitor/Monitor.java
##########
@@ -484,6 +485,17 @@ public void run() {
}
}).start();
+ Threads.createThread("Compaction fetcher", () -> {
+ while (true) {
+ try {
+ fetchCompactions();
+ } catch (Exception e) {
+ log.warn("{}", e.getMessage(), e);
+ }
+ sleepUninterruptibly(5, TimeUnit.SECONDS);
+ }
+ }).start();
+
Review comment:
The problem with this pattern is that there's a constant background
thread doing RPC calls to the tservers to collect these stats, even if nobody
is accessing the page on the monitor. And, it has to talk to every tserver, of
which there could be thousands. This is a lot of constant activity that might
not even be needed. The general pattern of the monitor is to avoid refreshing
data if nobody is accessing the page, and to limit the refresh of the data
shown on the page to collect it no more frequently than once every 5 seconds.
This is how we collect the "mmi" object, anyway.
Fast display should not bog down the cluster like this.
##########
File path: server/monitor/src/main/java/org/apache/accumulo/monitor/Monitor.java
##########
@@ -589,6 +624,33 @@ private void fetchScans() throws Exception {
}
}
+ private void fetchCompactions() throws Exception {
+ ServerContext context = getContext();
+ for (String server : context.instanceOperations().getTabletServers()) {
+ final HostAndPort parsedServer = HostAndPort.fromString(server);
+ Client tserver = ThriftUtil.getTServerClient(parsedServer, context);
+ try {
+ var compacts = tserver.getActiveCompactions(null, context.rpcCreds());
+ synchronized (allCompactions) {
+ allCompactions.put(parsedServer, new CompactionStats(compacts));
+ }
+ } catch (Exception ex) {
+ log.debug("Failed to get active compactions from {}", server, ex);
+ } finally {
+ ThriftUtil.returnClient(tserver);
+ }
+ }
+ // Age off old compaction information
+ var entryIter = allCompactions.entrySet().iterator();
+ long now = System.currentTimeMillis();
+ while (entryIter.hasNext()) {
+ var entry = entryIter.next();
+ if (now - entry.getValue().fetched > 5 * 60 * 1000) {
Review comment:
This should use nanoTime to compute time durations, to avoid system
clock adjustments affecting the computation.
##########
File path:
server/monitor/src/main/java/org/apache/accumulo/monitor/rest/compactions/CompactionInfo.java
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.accumulo.monitor.rest.compactions;
+
+import org.apache.accumulo.core.master.thrift.TabletServerStatus;
+
+/**
+ * Generates a compaction info JSON object
+ *
+ * @since 2.1.0
+ */
+public class CompactionInfo {
+
+ // Variable names become JSON keys
+ public String server;
+
+ public long count;
+ public Long oldest;
+
+ public CompactionInfo() {}
+
+ /**
+ * Stores new compaction information
+ *
+ * @param tserverInfo
+ * status of the tserver
+ * @param count
+ * number of compactions
+ * @param oldest
+ * time of oldest compaction
+ */
+ public CompactionInfo(TabletServerStatus tserverInfo, long count, Long
oldest) {
Review comment:
Not sure, but OptionalLong might be better here, rather than passing a
nullable boxed version of Long.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]