From 74df8a82a341f3bbdd1b5421a56c0c26209c1280 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 17 Sep 2021 08:45:47 +0200 Subject: [PATCH] Memory threshold Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/Node.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/bungeecore/Node.java b/src/de/steamwar/bungeecore/Node.java index d63093d0..5336491f 100644 --- a/src/de/steamwar/bungeecore/Node.java +++ b/src/de/steamwar/bungeecore/Node.java @@ -34,6 +34,7 @@ public abstract class Node { private static final List JVM_ARGS = Arrays.asList("-Dlog4j.configurationFile=log4j2.xml", "-server", "-Xms128M", "-XX:+UseCompressedOops", "-XX:+TieredCompilation", "-XX:TargetSurvivorRatio=90", "-XX:SurvivorRatio=8", "-XX:MaxTenuringThreshold=15", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseBiasedLocking", "-XX:UseSSE=3", "-XX:+UseCodeCacheFlushing", "-XX:+UseThreadPriorities", "-XX:+AggressiveOpts", "-XX:+ReduceSignalUsage", "-XX:+UseInterpreter", "-XX:+UseSharedSpaces", "-XX:AllocatePrefetchStyle=1", "-XX:+AlwaysCompileLoopMethods", "-XX:+UseConcMarkSweepGC", "-XX:+RewriteFrequentPairs", "-XX:+OptimizeStringConcat", "-XX:+CMSCleanOnEnter", "-XX:+UseInlineCaches"); private static final List JVM8_ARGS = Arrays.asList("-XX:ThreadPriorityPolicy=42", "-XX:SharedReadOnlySize=30m", "-XX:+UseFastEmptyMethods", "-XX:+UseFastAccessorMethods"); + private static final long minFreeMem = 4L * 1024 * 1024; // 4 GB private static final List nodes = new ArrayList<>(); public static Node local = null; @@ -160,7 +161,7 @@ public abstract class Node { throw new SecurityException("Could not read local cpu", e); } - return cpuLoad / cores + (totalMem - freeMem) / totalMem; + return cpuLoad / cores + freeMem > minFreeMem ? 0 : ((totalMem - freeMem) / totalMem); } } @@ -250,7 +251,7 @@ public abstract class Node { double totalMem = Double.parseDouble(bufferedReader.readLine().replaceAll(" +", " ").split(" ")[1]); bufferedReader.readLine(); double freeMem = Double.parseDouble(bufferedReader.readLine().replaceAll(" +", " ").split(" ")[1]); - return cpuLoad / cores + (totalMem - freeMem) / totalMem; + return cpuLoad / cores + freeMem > minFreeMem ? 0 : ((totalMem - freeMem) / totalMem); } catch (IOException e) { BungeeCore.get().getLogger().log(Level.SEVERE, "Could read load", e); return Double.POSITIVE_INFINITY;