From 95fe42a26b3ac3051a94bb46a17560c1b47615cd Mon Sep 17 00:00:00 2001 From: imbajin Date: Thu, 10 Oct 2024 19:03:15 +0800 Subject: [PATCH] improve code --- .../hugegraph/config/ServerOptions.java | 2 +- .../static/conf/rest-server.properties | 18 +++++------------ .../hugegraph/dist/HugeGraphServer.java | 2 +- .../apache/hugegraph/dist/MemoryMonitor.java | 20 +++++++++---------- 4 files changed, 16 insertions(+), 26 deletions(-) diff --git a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/config/ServerOptions.java b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/config/ServerOptions.java index 5c5aa86e3d..f4b259cc41 100644 --- a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/config/ServerOptions.java +++ b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/config/ServerOptions.java @@ -43,7 +43,7 @@ public static synchronized ServerOptions instance() { public static final ConfigOption REST_SERVER_URL = new ConfigOption<>( "restserver.url", - "The url for listening of hugeserver.", + "The url for listening of graph server.", disallowEmpty(), "http://127.0.0.1:8080" ); 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..a2e03296b4 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 @@ -7,10 +7,6 @@ restserver.url=http://127.0.0.1:8080 graphs=./conf/graphs -# The maximum thread ratio for batch writing, only take effect if the batch.max_write_threads is 0 -batch.max_write_ratio=80 -batch.max_write_threads=0 - # configuration of arthas arthas.telnet_port=8562 arthas.http_port=8561 @@ -18,18 +14,14 @@ arthas.ip=127.0.0.1 arthas.disabled_commands=jad # authentication configs -# choose 'org.apache.hugegraph.auth.StandardAuthenticator' or -# 'org.apache.hugegraph.auth.ConfigAuthenticator' -#auth.authenticator= - -# for StandardAuthenticator mode +#auth.authenticator=org.apache.hugegraph.auth.StandardAuthenticator #auth.graph_store=hugegraph # auth client config #auth.remote_url=127.0.0.1:8899,127.0.0.1:8898,127.0.0.1:8897 -# for ConfigAuthenticator mode -#auth.admin_token= -#auth.user_tokens=[] +# The maximum thread ratio for batch writing, only take effect if the batch.max_write_threads is 0 +batch.max_write_ratio=80 +batch.max_write_threads=0 # rpc server configs for multi graph-servers or raft-servers rpc.server_host=127.0.0.1 @@ -54,6 +46,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..b016332a76 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,9 @@ 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(); } @@ -85,8 +85,7 @@ private Thread getHighestMemoryThread() { continue; } - long threadMemory = - threadMXBean.getThreadAllocatedBytes(thread.getId()); + long threadMemory = threadMXBean.getThreadAllocatedBytes(thread.getId()); if (threadMemory > highestMemory) { highestMemory = threadMemory; highestThread = thread; @@ -99,14 +98,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 +117,6 @@ public void stop() { return; } this.scheduler.shutdownNow(); - LOG.info("Memory monitoring stoped."); + LOG.info("Memory monitoring stopped."); } }