Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Increase the usage of MetaSpace in computing #85

Merged
merged 9 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@
import lombok.Getter;
import lombok.Setter;

import java.lang.management.MemoryPoolMXBean;
import java.util.Date;

import static com.alipay.sofa.serverless.arklet.core.command.record.ProcessRecord.Status.EXECUTING;
import static com.alipay.sofa.serverless.arklet.core.command.record.ProcessRecord.Status.FAILED;
import static com.alipay.sofa.serverless.arklet.core.command.record.ProcessRecord.Status.INITIALIZED;
import static com.alipay.sofa.serverless.arklet.core.command.record.ProcessRecord.Status.SUCCEEDED;
import static com.alipay.sofa.serverless.arklet.core.command.record.ProcessRecord.Status.*;
sususama marked this conversation as resolved.
Show resolved Hide resolved

/**
* @author: yuanyuan
Expand All @@ -39,6 +37,8 @@ public class ProcessRecord {

private static final ArkletLogger LOGGER = ArkletLoggerFactory.getDefaultLogger();

private MemoryPoolMXBean metaSpaceMXBean;

private String requestId;

private ArkBizMeta arkBizMeta;
Expand All @@ -55,14 +55,20 @@ public class ProcessRecord {

private Date startTime;

private long startSpace;

private long startTimestamp;

private Date endTime;

private long endSpace;

private long endTimestamp;

private long elapsedTime;

private long elapsedSpace;

public enum Status {

INITIALIZED("INITIALIZED"),
Expand All @@ -89,6 +95,8 @@ public void setName(String name) {
}

public void markFinishTime() {
setEndSpace(getMetaSpaceMXBean().getUsage().getUsed());
setElapsedSpace(getEndSpace() - getStartSpace());
Date date = new Date();
setEndTime(date);
setEndTimestamp(date.getTime());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
*/
package com.alipay.sofa.serverless.arklet.core.command.record;

import com.alipay.sofa.serverless.arklet.core.command.meta.InputMeta;
import com.alipay.sofa.serverless.arklet.core.command.meta.bizops.ArkBizMeta;
import org.apache.commons.lang3.StringUtils;

import java.lang.management.ManagementFactory;
import java.lang.management.MemoryPoolMXBean;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -58,10 +59,17 @@ public static List<ProcessRecord> getProcessRecordsByStatus(String status) {

public static ProcessRecord createProcessRecord(String rid, ArkBizMeta arkBizMeta) {
ProcessRecord pr = new ProcessRecord();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ProcessRecord只有在async时才有

List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
MemoryPoolMXBean metaSpaceMXBean = null;
for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans)
if (memoryPoolMXBean.getName().equals("Metaspace"))
metaSpaceMXBean = memoryPoolMXBean;
pr.setRequestId(rid);
pr.setArkBizMeta(arkBizMeta);
pr.setStatus(INITIALIZED);
Date date = new Date();
pr.setMetaSpaceMXBean(metaSpaceMXBean);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以使用static缓存metaSpaceMXBean,不要放在成员变量里

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我在这里将metaSpaceMXBean放进成员变量里是因为后面在ProcessRecord里面需要再次用到metaSpaceMXBean,如果不放的话可以每次用的时候都在memoryPoolMXBeans里面重新遍历出来metaSpaceMXBean

pr.setStartSpace(metaSpaceMXBean.getUsage().getUsed());
pr.setStartTime(date);
pr.setStartTimestamp(date.getTime());
processRecords.put(rid, pr);
Expand Down