From 34e9cce05adba32e6ec7b0fd4e4c151bb2bf8027 Mon Sep 17 00:00:00 2001 From: sususama <1023605039@qq.com> Date: Sat, 9 Sep 2023 22:28:19 +0800 Subject: [PATCH 1/7] Increase the usage of MetaSpace in computing --- .../core/command/record/ProcessRecord.java | 16 ++++++++++++---- .../core/command/record/ProcessRecordHolder.java | 10 +++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java index d3e1f62ff..dddf66db6 100644 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java @@ -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.*; /** * @author: yuanyuan @@ -39,6 +37,8 @@ public class ProcessRecord { private static final ArkletLogger LOGGER = ArkletLoggerFactory.getDefaultLogger(); + private MemoryPoolMXBean metaSpaceMXBean; + private String requestId; private ArkBizMeta arkBizMeta; @@ -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"), @@ -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()); diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecordHolder.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecordHolder.java index 01ccd4b75..61570f3e5 100644 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecordHolder.java +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecordHolder.java @@ -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; @@ -58,10 +59,17 @@ public static List getProcessRecordsByStatus(String status) { public static ProcessRecord createProcessRecord(String rid, ArkBizMeta arkBizMeta) { ProcessRecord pr = new ProcessRecord(); + List 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); + pr.setStartSpace(metaSpaceMXBean.getUsage().getUsed()); pr.setStartTime(date); pr.setStartTimestamp(date.getTime()); processRecords.put(rid, pr); From 9dfd8a905dd336fd7dfedd1c053e1a6feafad250 Mon Sep 17 00:00:00 2001 From: sususama <1023605039@qq.com> Date: Tue, 19 Sep 2023 22:41:48 +0800 Subject: [PATCH 2/7] fix import --- .../serverless/arklet/core/command/record/ProcessRecord.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java index dddf66db6..caf6c3e24 100644 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java @@ -25,7 +25,10 @@ import java.lang.management.MemoryPoolMXBean; import java.util.Date; -import static com.alipay.sofa.serverless.arklet.core.command.record.ProcessRecord.Status.*; +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; /** * @author: yuanyuan From d0a68a8c3bd3bf4a915cd539380fbd8331e82df3 Mon Sep 17 00:00:00 2001 From: sususama <1023605039@qq.com> Date: Wed, 20 Sep 2023 17:21:47 +0800 Subject: [PATCH 3/7] add test --- .../arklet/core/command/CommandTests.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java index 452294aea..d759a2886 100644 --- a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java @@ -16,7 +16,10 @@ */ package com.alipay.sofa.serverless.arklet.core.command; +import java.lang.management.ManagementFactory; +import java.lang.management.MemoryPoolMXBean; import java.util.HashMap; +import java.util.List; import java.util.Map; import com.alibaba.fastjson.JSONObject; @@ -29,6 +32,7 @@ import com.alipay.sofa.serverless.arklet.core.command.custom.CustomCommandHandler; import com.alipay.sofa.serverless.arklet.core.command.meta.Output; import com.alipay.sofa.serverless.arklet.core.command.record.ProcessRecord; +import com.sun.webkit.Timer; import org.junit.Assert; import org.junit.Test; @@ -73,6 +77,26 @@ 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()); + } + + @Test + public void testResourceStatistics() throws Exception { + List memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans(); + MemoryPoolMXBean metaSpaceMXBean = null; + for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) + if (memoryPoolMXBean.getName().equals("Metaspace")) + metaSpaceMXBean = memoryPoolMXBean; + Long beforeSpace = metaSpaceMXBean.getUsage().getUsed(); + Long beforeTime = System.currentTimeMillis(); +// 运行指令 + Long time = System.currentTimeMillis() - beforeTime; + Long usedSpace = metaSpaceMXBean.getUsage().getUsed() - beforeSpace; + System.out.println(time); + System.out.println(usedSpace); } } From ccccf62a35c9a9eb09c605a388263e22309b65eb Mon Sep 17 00:00:00 2001 From: sususama <1023605039@qq.com> Date: Wed, 20 Sep 2023 20:48:52 +0800 Subject: [PATCH 4/7] fix --- .../core/command/record/ProcessRecord.java | 2 +- .../arklet/core/health/HealthServiceImpl.java | 5 ++--- .../arklet/core/command/CommandTests.java | 20 +++---------------- .../core/command/HealthHandlerTest.java | 18 ++++++++++++++++- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java index caf6c3e24..06bd83ce9 100644 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java @@ -40,7 +40,7 @@ public class ProcessRecord { private static final ArkletLogger LOGGER = ArkletLoggerFactory.getDefaultLogger(); - private MemoryPoolMXBean metaSpaceMXBean; + private MemoryPoolMXBean metaSpaceMXBean; private String requestId; diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/health/HealthServiceImpl.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/health/HealthServiceImpl.java index dc4fb1b7a..2c63ba77a 100644 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/health/HealthServiceImpl.java +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/health/HealthServiceImpl.java @@ -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 indicators = new ConcurrentHashMap<>(3); diff --git a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java index d759a2886..8492026d2 100644 --- a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java @@ -18,6 +18,8 @@ import java.lang.management.ManagementFactory; import java.lang.management.MemoryPoolMXBean; +import java.lang.management.ThreadInfo; +import java.lang.management.ThreadMXBean; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -32,7 +34,7 @@ import com.alipay.sofa.serverless.arklet.core.command.custom.CustomCommandHandler; import com.alipay.sofa.serverless.arklet.core.command.meta.Output; import com.alipay.sofa.serverless.arklet.core.command.record.ProcessRecord; -import com.sun.webkit.Timer; + import org.junit.Assert; import org.junit.Test; @@ -83,20 +85,4 @@ public void testInstallHandler() throws InterruptedException { Assert.assertNotNull(processRecord1.getEndTime()); } - @Test - public void testResourceStatistics() throws Exception { - List memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans(); - MemoryPoolMXBean metaSpaceMXBean = null; - for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) - if (memoryPoolMXBean.getName().equals("Metaspace")) - metaSpaceMXBean = memoryPoolMXBean; - Long beforeSpace = metaSpaceMXBean.getUsage().getUsed(); - Long beforeTime = System.currentTimeMillis(); -// 运行指令 - Long time = System.currentTimeMillis() - beforeTime; - Long usedSpace = metaSpaceMXBean.getUsage().getUsed() - beforeSpace; - System.out.println(time); - System.out.println(usedSpace); - } - } diff --git a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/HealthHandlerTest.java b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/HealthHandlerTest.java index 8c2ec0dc8..cae78df33 100644 --- a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/HealthHandlerTest.java +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/HealthHandlerTest.java @@ -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; @@ -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); } From 31262feb26c713447a4c34da1cc92d9d9458a0a1 Mon Sep 17 00:00:00 2001 From: sususama <1023605039@qq.com> Date: Wed, 20 Sep 2023 20:50:14 +0800 Subject: [PATCH 5/7] fix --- .../arklet/core/command/CommandTests.java | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java index 8492026d2..c68a89768 100644 --- a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java @@ -16,16 +16,7 @@ */ package com.alipay.sofa.serverless.arklet.core.command; -import java.lang.management.ManagementFactory; -import java.lang.management.MemoryPoolMXBean; -import java.lang.management.ThreadInfo; -import java.lang.management.ThreadMXBean; -import java.util.HashMap; -import java.util.List; -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; @@ -34,10 +25,12 @@ import com.alipay.sofa.serverless.arklet.core.command.custom.CustomCommandHandler; import com.alipay.sofa.serverless.arklet.core.command.meta.Output; import com.alipay.sofa.serverless.arklet.core.command.record.ProcessRecord; - import org.junit.Assert; import org.junit.Test; +import java.util.HashMap; +import java.util.Map; + /** * @author mingmen * @date 2023/6/26 From a3dccdb13bc20ae00f4e7bfe540a5b2fff5914f9 Mon Sep 17 00:00:00 2001 From: sususama <1023605039@qq.com> Date: Thu, 21 Sep 2023 22:42:12 +0800 Subject: [PATCH 6/7] fix --- .../core/command/CommandServiceImpl.java | 4 ++ .../core/command/record/MetaSpaceRecord.java | 40 +++++++++++++++++++ .../core/command/record/ProcessRecord.java | 3 -- .../command/record/ProcessRecordHolder.java | 7 ---- .../arklet/core/command/CommandTests.java | 2 +- 5 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/MetaSpaceRecord.java diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/CommandServiceImpl.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/CommandServiceImpl.java index b566a3c75..037a0c99f 100644 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/CommandServiceImpl.java +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/CommandServiceImpl.java @@ -41,6 +41,7 @@ import com.alipay.sofa.serverless.arklet.core.command.meta.Command; import com.alipay.sofa.serverless.arklet.core.command.meta.InputMeta; import com.alipay.sofa.serverless.arklet.core.command.meta.Output; +import com.alipay.sofa.serverless.arklet.core.command.record.MetaSpaceRecord; import com.alipay.sofa.serverless.arklet.core.command.record.ProcessRecord; import com.alipay.sofa.serverless.arklet.core.command.record.ProcessRecordHolder; import com.alipay.sofa.serverless.arklet.core.common.exception.ArkletInitException; @@ -110,6 +111,7 @@ public Output process(String cmd, Map content) throws CommandValidationExcept ArkBizMeta arkBizMeta = (ArkBizMeta) input; AssertUtils.assertNotNull(arkBizMeta, "when execute bizOpsHandler, arkBizMeta should not be null"); + final MetaSpaceRecord metaSpaceRecord = new MetaSpaceRecord(); if (arkBizMeta.isAsync()) { String requestId = arkBizMeta.getRequestId(); if (ProcessRecordHolder.getProcessRecord(requestId) != null) { @@ -127,6 +129,7 @@ public Output process(String cmd, Map content) throws CommandValidationExcept processRecord.fail("command conflict, exist unfinished command for this biz"); } else { processRecord.start(); + processRecord.setStartSpace(metaSpaceRecord.getMetaSpaceMXBean().getUsage().getUsed()); Output output = handler.handle(input); if (output.success()) { processRecord.success(); @@ -138,6 +141,7 @@ public Output process(String cmd, Map content) throws CommandValidationExcept processRecord.fail(throwable.getMessage(), throwable); LOGGER.error("Error happened when handling command, requestId=" + requestId, throwable); } finally { + processRecord.setEndSpace(metaSpaceRecord.getMetaSpaceMXBean().getUsage().getUsed()); processRecord.markFinishTime(); BizOpsCommandCoordinator .unlock(arkBizMeta.getBizName(), arkBizMeta.getBizVersion()); diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/MetaSpaceRecord.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/MetaSpaceRecord.java new file mode 100644 index 000000000..3da1e1e74 --- /dev/null +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/MetaSpaceRecord.java @@ -0,0 +1,40 @@ +/* + * 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.record; + +import java.lang.management.ManagementFactory; +import java.lang.management.MemoryPoolMXBean; +import java.util.List; + +/** + * @author sususama + * @since 2023-09-21 + */ + +public class MetaSpaceRecord { + private static MemoryPoolMXBean metaSpaceMXBean; + static { + List memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans(); + for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) + if (memoryPoolMXBean.getName().equals("Metaspace")) + metaSpaceMXBean = memoryPoolMXBean; + } + + public MemoryPoolMXBean getMetaSpaceMXBean() { + return metaSpaceMXBean; + } +} diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java index 06bd83ce9..46df73911 100644 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java @@ -40,8 +40,6 @@ public class ProcessRecord { private static final ArkletLogger LOGGER = ArkletLoggerFactory.getDefaultLogger(); - private MemoryPoolMXBean metaSpaceMXBean; - private String requestId; private ArkBizMeta arkBizMeta; @@ -98,7 +96,6 @@ public void setName(String name) { } public void markFinishTime() { - setEndSpace(getMetaSpaceMXBean().getUsage().getUsed()); setElapsedSpace(getEndSpace() - getStartSpace()); Date date = new Date(); setEndTime(date); diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecordHolder.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecordHolder.java index 61570f3e5..24899fc41 100644 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecordHolder.java +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecordHolder.java @@ -59,17 +59,10 @@ public static List getProcessRecordsByStatus(String status) { public static ProcessRecord createProcessRecord(String rid, ArkBizMeta arkBizMeta) { ProcessRecord pr = new ProcessRecord(); - List 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); - pr.setStartSpace(metaSpaceMXBean.getUsage().getUsed()); pr.setStartTime(date); pr.setStartTimestamp(date.getTime()); processRecords.put(rid, pr); diff --git a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java index c68a89768..a2147332c 100644 --- a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java @@ -66,6 +66,7 @@ public void testInstallHandler() throws InterruptedException { Assert.assertNotNull(output); ProcessRecord processRecord = (ProcessRecord) output.getData(); Assert.assertNotNull(processRecord); + Assert.assertNotNull(processRecord.getEndSpace()); QueryBizOpsHandler.Input input1 = new QueryBizOpsHandler.Input(); input1.setRequestId(rid); @@ -75,7 +76,6 @@ public void testInstallHandler() throws InterruptedException { ProcessRecord processRecord1 = (ProcessRecord) output1.getData(); Assert.assertNotNull(processRecord1); Assert.assertNotNull(processRecord1.getEndSpace()); - Assert.assertNotNull(processRecord1.getEndTime()); } } From 5039b8b174f2a41fa4785705ef1ec2a9402e3a64 Mon Sep 17 00:00:00 2001 From: sususama <1023605039@qq.com> Date: Thu, 21 Sep 2023 22:46:03 +0800 Subject: [PATCH 7/7] fix --- .../arklet/core/command/CommandServiceImpl.java | 5 ++++- .../sofa/serverless/arklet/core/command/meta/Output.java | 9 +++++++++ .../arklet/core/command/record/ProcessRecord.java | 1 - .../arklet/core/command/record/ProcessRecordHolder.java | 2 -- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/CommandServiceImpl.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/CommandServiceImpl.java index 037a0c99f..093d36fb4 100644 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/CommandServiceImpl.java +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/CommandServiceImpl.java @@ -164,7 +164,10 @@ public Output process(String cmd, Map content) throws CommandValidationExcept arkBizMeta.getBizName(), arkBizMeta.getBizVersion()).getId())); } try { - return handler.handle(input); + final long startSpace = metaSpaceRecord.getMetaSpaceMXBean().getUsage().getUsed(); + Output output = handler.handle(input); + output.setElapsedSpace(metaSpaceRecord.getMetaSpaceMXBean().getUsage().getUsed() - startSpace); + return output; } finally { BizOpsCommandCoordinator .unlock(arkBizMeta.getBizName(), arkBizMeta.getBizVersion()); diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/meta/Output.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/meta/Output.java index c997ed464..57ffe0457 100644 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/meta/Output.java +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/meta/Output.java @@ -26,6 +26,7 @@ public class Output { private ResponseCode code; private String message; + private long elapsedSpace; private T data; private Output() { @@ -84,4 +85,12 @@ public T getData() { public void setData(T data) { this.data = data; } + + public void setElapsedSpace(long elapsedSpace) { + this.elapsedSpace = elapsedSpace; + } + + public long getElapsedSpace() { + return this.elapsedSpace; + } } diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java index 46df73911..c7f8c561f 100644 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java @@ -22,7 +22,6 @@ 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; diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecordHolder.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecordHolder.java index 24899fc41..d270209cf 100644 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecordHolder.java +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecordHolder.java @@ -19,8 +19,6 @@ 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;