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 7 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,6 +22,7 @@
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;
Expand All @@ -39,6 +40,8 @@ public class ProcessRecord {

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

private MemoryPoolMXBean metaSpaceMXBean;

private String requestId;

private ArkBizMeta arkBizMeta;
Expand All @@ -55,14 +58,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 +98,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
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@
@Singleton
public class HealthServiceImpl implements HealthService {

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

private final Map<String, Indicator> indicators = new ConcurrentHashMap<>(3);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
*/
package com.alipay.sofa.serverless.arklet.core.command;

import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;

import com.alipay.sofa.serverless.arklet.core.BaseTest;
import com.alipay.sofa.serverless.arklet.core.command.builtin.BuiltinCommand;
import com.alipay.sofa.serverless.arklet.core.command.builtin.handler.InstallBizHandler;
Expand All @@ -32,6 +28,9 @@
import org.junit.Assert;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

/**
* @author mingmen
* @date 2023/6/26
Expand Down Expand Up @@ -73,6 +72,10 @@ public void testInstallHandler() throws InterruptedException {
Map map1 = JSONObject.parseObject(JSONObject.toJSONString(input1), Map.class);
Output<?> output1 = commandService.process(BuiltinCommand.QUERY_BIZ_OPS.getId(), map1);
Assert.assertNotNull(output1);
ProcessRecord processRecord1 = (ProcessRecord) output1.getData();
Assert.assertNotNull(processRecord1);
Assert.assertNotNull(processRecord1.getEndSpace());
Assert.assertNotNull(processRecord1.getEndTime());
}

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alipay.sofa.serverless.arklet.core.command;

import com.alipay.sofa.serverless.arklet.core.BaseTest;
Expand All @@ -12,7 +28,7 @@
*/
public class HealthHandlerTest extends BaseTest {

private void testValidate(Input input) throws CommandValidationException{
private void testValidate(Input input) throws CommandValidationException {
HealthHandler handler = (HealthHandler) commandService.getHandler(BuiltinCommand.HEALTH);
handler.validate(input);
}
Expand Down