You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2021/09/14 21:56:24 UTC

[brooklyn-server] 05/27: GC periodic-persistence tasks immediately

This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git

commit 88fc1a57ce8144a8a19210385957b643ff7f146e
Author: Alex Heneveld <al...@cloudsoftcorp.com>
AuthorDate: Mon Sep 13 22:17:42 2021 +0100

    GC periodic-persistence tasks immediately
    
    cut down debug logging about GC when system is doing nothing
---
 .../mgmt/internal/BrooklynGarbageCollector.java    | 22 ++++++++++++++++------
 .../util/core/task/BasicExecutionManager.java      |  9 +++++++--
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/BrooklynGarbageCollector.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/BrooklynGarbageCollector.java
index 2d932fd..ca1e075 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/BrooklynGarbageCollector.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/BrooklynGarbageCollector.java
@@ -18,6 +18,7 @@
  */
 package org.apache.brooklyn.core.mgmt.internal;
 
+import com.google.common.annotations.VisibleForTesting;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
@@ -35,6 +36,7 @@ import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import java.util.stream.Collectors;
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.location.Location;
 import org.apache.brooklyn.api.mgmt.HasTaskChildren;
@@ -154,6 +156,7 @@ public class BrooklynGarbageCollector {
             return (end1 < end2) ? -1 : ((end1 == end2) ? 0 : 1);
         }
     };
+    protected final static Comparator<Task<?>> TASKS_NEWEST_FIRST_COMPARATOR = (t1,t2) -> -TASKS_OLDEST_FIRST_COMPARATOR.compare(t1, t2);
     
     private final BasicExecutionManager executionManager;
     @SuppressWarnings("unused")  // TODO remove BrooklynStorage altogether?
@@ -330,7 +333,8 @@ public class BrooklynGarbageCollector {
      * Deletes old tasks. The age/number of tasks to keep is controlled by fields like 
      * {@link #MAX_TASKS_PER_TAG} and {@link #MAX_TASKS_PER_TAG}.
      */
-    protected synchronized int gcTasks() {
+    @VisibleForTesting
+    public synchronized int gcTasks() {
         // NB: be careful with memory usage here: have seen OOME if we get crazy lots of tasks.
         // hopefully the use new limits, filters, and use of live lists in some places (added Sep 2014) will help.
         // 
@@ -607,13 +611,19 @@ public class BrooklynGarbageCollector {
             LOG.debug("Got CME inspecting tasks, with "+tasksToConsiderDeleting.size()+" found for deletion: "+e);
         }
 
-        if (LOG.isDebugEnabled())
-            LOG.debug("brooklyn-gc detected "+taskTagsInCategoryOverCapacity.size()+" "+category+" "
+        Collections.sort(tasksToConsiderDeleting, TASKS_OLDEST_FIRST_COMPARATOR);
+
+        if (LOG.isDebugEnabled()) {
+            MutableList<Task<?>> tasksToConsiderDeletingNewest = MutableList.copyOf(tasksToConsiderDeleting);
+            Collections.sort(tasksToConsiderDeletingNewest, TASKS_NEWEST_FIRST_COMPARATOR);
+            LOG.debug("brooklyn-gc detected " + taskTagsInCategoryOverCapacity.size() + " " + category + " "
                     + "tags over capacity, expiring old tasks; "
-                    + tasksToConsiderDeleting.size()+" tasks under consideration; categories are: "
-                    + taskTagsInCategoryOverCapacity);
+                    + tasksToConsiderDeleting.size() + " tasks under consideration; categories are: "
+                    + taskTagsInCategoryOverCapacity + "; including "
+                    + tasksToConsiderDeleting.stream().limit(5).collect(Collectors.toList()) + " ... "
+                    + tasksToConsiderDeletingNewest.stream().limit(5).collect(Collectors.toList()) );
+        }
 
-        Collections.sort(tasksToConsiderDeleting, TASKS_OLDEST_FIRST_COMPARATOR);
         // now try deleting tasks which are overcapacity for each (non-entity) tag
         int deleted = 0;
         for (Task<?> task: tasksToConsiderDeleting) {
diff --git a/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionManager.java b/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionManager.java
index f1496fc..d7af2c0 100644
--- a/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionManager.java
+++ b/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionManager.java
@@ -108,7 +108,7 @@ public class BasicExecutionManager implements ExecutionManager {
     public static final String LOGGING_MDC_KEY_ENTITY_IDS = "entity.ids";
     public static final String LOGGING_MDC_KEY_TASK_ID = "task.id";
 
-    private static final boolean SCHEDULED_TASKS_COUNT_AS_ACTIVE = false;
+    private static final boolean SCHEDULED_TASKS_COUNT_AS_ACTIVE = true;
 
     private boolean jitterThreads = BrooklynFeatureEnablement.isEnabled(BrooklynFeatureEnablement.FEATURE_JITTER_THREADS);
     private int jitterThreadsMaxDelay = Integer.getInteger(JITTER_THREADS_MAX_DELAY_PROPERTY, 200);
@@ -967,7 +967,7 @@ public class BasicExecutionManager implements ExecutionManager {
      * but before doing any of the task's work, so that we can update bookkeeping and notify callbacks */
     protected void internalBeforeStart(Map<?,?> flags, Task<?> task, boolean skipIncrementCounter, boolean allowJitter, boolean startingThisThreadMightEndElsewhere) {
         int count = skipIncrementCounter ? activeTaskCount.get() : activeTaskCount.incrementAndGet();
-        if (count % 1000==0) {
+        if (count % 1000==0 && count>0) {
             log.warn("High number of active tasks: task #"+count+" is "+task);
         }
         
@@ -1119,6 +1119,11 @@ public class BasicExecutionManager implements ExecutionManager {
             }
             ((TaskInternal<?>)task).setThread(null);
 
+            // if uninteresting and transient and scheduled, go ahead and remove from task tags also, so it won't be reported as GC'd
+            if (BrooklynTaskTags.isTransient(task) && UNINTERESTING_TASK_NAMES.contains(task.getDisplayName()) && task.getSubmittedByTask() instanceof ScheduledTask) {
+                deleteTask(task);
+            }
+
         } finally {
             try {
                 if (error!=null) {