Skip to content

Commit

Permalink
improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
imbajin committed Oct 10, 2024
1 parent 310c8d7 commit 95fe42a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static synchronized ServerOptions instance() {
public static final ConfigOption<String> 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"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,21 @@ 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
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
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ 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 '{}'.",
memoryUsagePercentage, MEMORY_MONITOR_THRESHOLD);
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);
Expand All @@ -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();
}

Expand All @@ -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;
Expand All @@ -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,
Expand All @@ -119,6 +117,6 @@ public void stop() {
return;
}
this.scheduler.shutdownNow();
LOG.info("Memory monitoring stoped.");
LOG.info("Memory monitoring stopped.");
}
}

0 comments on commit 95fe42a

Please sign in to comment.