You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by GitBox <gi...@apache.org> on 2022/07/26 12:46:56 UTC
[GitHub] [accumulo] milleruntime commented on a diff in pull request #2827: refactor GarbageCollectionLogger so one instance per context
milleruntime commented on code in PR #2827:
URL: https://github.com/apache/accumulo/pull/2827#discussion_r929920538
##########
server/base/src/main/java/org/apache/accumulo/server/GarbageCollectionLogger.java:
##########
@@ -22,109 +22,113 @@
import java.lang.management.ManagementFactory;
import java.util.HashMap;
import java.util.List;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
-import org.apache.accumulo.core.conf.AccumuloConfiguration;
import org.apache.accumulo.core.conf.Property;
import org.apache.accumulo.core.util.Halt;
+import org.apache.accumulo.core.util.threads.ThreadPools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class GarbageCollectionLogger {
private static final Logger log = LoggerFactory.getLogger(GarbageCollectionLogger.class);
+ private final ServerContext context;
+
private final HashMap<String,Long> prevGcTime = new HashMap<>();
private long lastMemorySize = 0;
private long gcTimeIncreasedCount = 0;
- private static long lastMemoryCheckTime = 0;
- private static final Lock memCheckTimeLock = new ReentrantLock();
-
- public void logGCInfo(AccumuloConfiguration conf) {
+ private long lastMemoryCheckTime = 0;
- memCheckTimeLock.lock();
- try {
- final long now = System.currentTimeMillis();
+ private static final long TIME_BETWEEN_GC_CHECKS_MIN = 5;
- List<GarbageCollectorMXBean> gcmBeans = ManagementFactory.getGarbageCollectorMXBeans();
- Runtime rt = Runtime.getRuntime();
+ public GarbageCollectionLogger(final ServerContext context) {
+ this.context = context;
- StringBuilder sb = new StringBuilder("gc");
+ ScheduledFuture<?> future = context.getScheduledExecutor()
+ .scheduleWithFixedDelay(this::logGCInfo, 0, TIME_BETWEEN_GC_CHECKS_MIN, TimeUnit.MINUTES);
+ ThreadPools.watchNonCriticalScheduledTask(future);
+ }
- boolean sawChange = false;
+ public synchronized void logGCInfo() {
Review Comment:
There is a separate thread that gets started when the tserver is starting up but other threads call this method as well. I don't know why we have both the separate thread and external calls to this logger. The check for the static time was added because of an old complex issue: https://issues.apache.org/jira/browse/ACCUMULO-3084
--
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: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org