diff --git a/hugegraph-server/hugegraph-dist/src/assembly/static/conf/rest-server.properties b/hugegraph-server/hugegraph-dist/src/assembly/static/conf/rest-server.properties index 0c568823c4..9d6bb2ca82 100644 --- a/hugegraph-server/hugegraph-dist/src/assembly/static/conf/rest-server.properties +++ b/hugegraph-server/hugegraph-dist/src/assembly/static/conf/rest-server.properties @@ -54,6 +54,6 @@ server.role=master # slow query log log.slow_query_threshold=1000 -# jvm memory usage monitor +# jvm(in-heap) memory usage monitor, set 1 to disable it memory_monitor.threshold=0.85 memory_monitor.period=2000 diff --git a/hugegraph-server/hugegraph-dist/src/main/java/org/apache/hugegraph/dist/HugeGraphServer.java b/hugegraph-server/hugegraph-dist/src/main/java/org/apache/hugegraph/dist/HugeGraphServer.java index da45726116..2652324f44 100644 --- a/hugegraph-server/hugegraph-dist/src/main/java/org/apache/hugegraph/dist/HugeGraphServer.java +++ b/hugegraph-server/hugegraph-dist/src/main/java/org/apache/hugegraph/dist/HugeGraphServer.java @@ -80,7 +80,7 @@ public HugeGraphServer(String gremlinServerConf, String restServerConf) System.setSecurityManager(securityManager); } - // Start Memory Monitor Task + // Start (In-Heap) Memory Monitor this.memoryMonitor = new MemoryMonitor(restServerConf); this.memoryMonitor.start(); } diff --git a/hugegraph-server/hugegraph-dist/src/main/java/org/apache/hugegraph/dist/MemoryMonitor.java b/hugegraph-server/hugegraph-dist/src/main/java/org/apache/hugegraph/dist/MemoryMonitor.java index 876f00ad58..18b7cc170f 100644 --- a/hugegraph-server/hugegraph-dist/src/main/java/org/apache/hugegraph/dist/MemoryMonitor.java +++ b/hugegraph-server/hugegraph-dist/src/main/java/org/apache/hugegraph/dist/MemoryMonitor.java @@ -47,7 +47,7 @@ public MemoryMonitor(String restServerConf) { } private void runMemoryDetect() { - double memoryUsagePercentage = getMemoryUsagePercentage(); + double memoryUsagePercentage = getMemoryUsageRatio(); if (memoryUsagePercentage > MEMORY_MONITOR_THRESHOLD) { LOG.warn("JVM memory usage is '{}', exceeding the threshold of '{}'.", @@ -55,7 +55,7 @@ private void runMemoryDetect() { System.gc(); LOG.warn("Trigger System.gc()"); - double doubleCheckUsage = getMemoryUsagePercentage(); + double doubleCheckUsage = getMemoryUsageRatio(); if (doubleCheckUsage > MEMORY_MONITOR_THRESHOLD) { LOG.warn("JVM memory usage is '{}', exceeding the threshold of '{}'.", doubleCheckUsage, MEMORY_MONITOR_THRESHOLD); @@ -64,9 +64,8 @@ private void runMemoryDetect() { } } - private double getMemoryUsagePercentage() { - MemoryUsage heapMemoryUsage = - ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); + private double getMemoryUsageRatio() { + MemoryUsage heapMemoryUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); return (double) heapMemoryUsage.getUsed() / heapMemoryUsage.getMax(); } @@ -79,14 +78,12 @@ private Thread getHighestMemoryThread() { Thread[] threads = new Thread[Thread.activeCount()]; Thread.enumerate(threads); for (Thread thread : threads) { - if (thread.getState() != Thread.State.RUNNABLE || - thread.getName() == null || + if (thread.getState() != Thread.State.RUNNABLE || thread.getName() == null || !thread.getName().startsWith("grizzly-http-server-")) { continue; } - long threadMemory = - threadMXBean.getThreadAllocatedBytes(thread.getId()); + long threadMemory = threadMXBean.getThreadAllocatedBytes(thread.getId()); if (threadMemory > highestMemory) { highestMemory = threadMemory; highestThread = thread; @@ -99,14 +96,13 @@ private void interruptHighestMemoryThread() { Thread targetThread = getHighestMemoryThread(); if (targetThread != null) { targetThread.interrupt(); - LOG.warn("Send interrupt to '{}' thread", - targetThread.getName()); + LOG.warn("Send interrupt to '{}' thread", targetThread.getName()); } } public void start() { if (MEMORY_MONITOR_THRESHOLD >= 1.0) { - LOG.info("Invalid parameter, MEMORY_MONITOR_THRESHOLD should less than 1.0."); + LOG.info("Invalid parameter, MEMORY_MONITOR_THRESHOLD should ≤ 1.0."); return; } this.scheduler.scheduleAtFixedRate(this::runMemoryDetect, 0, MEMORY_MONITOR_DETECT_PERIOD, @@ -119,6 +115,6 @@ public void stop() { return; } this.scheduler.shutdownNow(); - LOG.info("Memory monitoring stoped."); + LOG.info("Memory monitoring stopped."); } }