forked from dragonwell-project/dragonwell8_jdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Add ResourceContainerMXBean, currently only support CPU resource amount. Test Plan: jtreg test/com/alibaba/ Reviewed-by: yuleil, zhengxiaolinX Issue: dragonwell-project/dragonwell8#206
- Loading branch information
joeyleeeeeee97
authored and
joeylee.lz
committed
Feb 8, 2021
1 parent
fd35688
commit e5bde46
Showing
18 changed files
with
304 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/share/classes/com/alibaba/management/ResourceContainerMXBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.alibaba.management; | ||
|
||
import java.lang.management.PlatformManagedObject; | ||
import java.util.List; | ||
|
||
public interface ResourceContainerMXBean extends PlatformManagedObject { | ||
List<Long> getAllContainerIds(); | ||
List<Long> getConstraintsById(long id); | ||
long getCPUResourceConsumedAmount(long id); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/share/classes/com/alibaba/rcm/ResourceContainerMXBeanImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.alibaba.rcm; | ||
|
||
import com.alibaba.management.ResourceContainerMXBean; | ||
import sun.management.Util; | ||
|
||
import javax.management.ObjectName; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class ResourceContainerMXBeanImpl implements ResourceContainerMXBean { | ||
private final static String TENANT_CONTAINER_MXBEAN_NAME = "com.alibaba.management:type=ResourceContainer"; | ||
|
||
@Override | ||
public List<Long> getAllContainerIds() { | ||
return ResourceContainerMonitor.getAllContainerIds(); | ||
} | ||
|
||
@Override | ||
public List<Long> getConstraintsById(long id) { | ||
return ResourceContainerMonitor.getConstraintsById(id).stream().map(c -> c.getValues()[0]).collect(Collectors.toList()); | ||
} | ||
|
||
|
||
@Override | ||
public long getCPUResourceConsumedAmount(long id) { | ||
ResourceContainer container = ResourceContainerMonitor.getContainerById(id); | ||
return container.getConsumedAmount(ResourceType.CPU_PERCENT); | ||
} | ||
|
||
@Override | ||
public ObjectName getObjectName() { | ||
return Util.newObjectName(TENANT_CONTAINER_MXBEAN_NAME); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/share/classes/com/alibaba/rcm/ResourceContainerMonitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.alibaba.rcm; | ||
|
||
import com.alibaba.rcm.Constraint; | ||
import com.alibaba.rcm.ResourceContainer; | ||
import com.alibaba.rcm.internal.AbstractResourceContainer; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.StreamSupport; | ||
|
||
public class ResourceContainerMonitor { | ||
private static Map<Long, ResourceContainer> tenantContainerMap = new HashMap<>(); | ||
private static long idGen = 0; | ||
|
||
public synchronized static long register(ResourceContainer resourceContainer) { | ||
long id = idGen++; | ||
tenantContainerMap.put(id, resourceContainer); | ||
return id; | ||
} | ||
|
||
public synchronized static ResourceContainer getContainerById(long id) { | ||
return tenantContainerMap.get(id); | ||
} | ||
|
||
public synchronized static List<Long> getAllContainerIds() { | ||
return new ArrayList<>(tenantContainerMap.keySet()); | ||
} | ||
|
||
public synchronized static List<Constraint> getConstraintsById(long id) { | ||
AbstractResourceContainer resourceContainer = (AbstractResourceContainer) tenantContainerMap.get(id); | ||
return StreamSupport | ||
.stream(resourceContainer.getConstraints().spliterator(), false) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* @test | ||
* @library /lib/testlibrary | ||
* @summary test RcmMXBeanTest | ||
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseWisp2 -XX:ActiveProcessorCount=4 RcmMXBeanTest | ||
*/ | ||
|
||
import com.alibaba.management.ResourceContainerMXBean; | ||
import com.alibaba.rcm.ResourceContainer; | ||
import com.alibaba.rcm.ResourceType; | ||
|
||
import javax.management.MBeanServer; | ||
import java.io.IOException; | ||
import java.lang.management.ManagementFactory; | ||
import java.util.Collections; | ||
import com.alibaba.wisp.engine.WispResourceContainerFactory; | ||
|
||
import static jdk.testlibrary.Asserts.*; | ||
|
||
public class RcmMXBeanTest { | ||
static ResourceContainerMXBean resourceContainerMXBean; | ||
|
||
public static void main(String[] args) throws Exception { | ||
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); | ||
try { | ||
resourceContainerMXBean = ManagementFactory.newPlatformMXBeanProxy(mbs, | ||
"com.alibaba.management:type=ResourceContainer", ResourceContainerMXBean.class); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
for (int i = 0; i < 3; i++) { | ||
ResourceContainer rc1 = WispResourceContainerFactory.instance() | ||
.createContainer(Collections.singletonList(ResourceType.CPU_PERCENT.newConstraint(80))); | ||
|
||
rc1.run(() -> { | ||
new Thread(() -> { | ||
while (true) { | ||
Thread.yield(); | ||
} | ||
}).start(); | ||
}); | ||
Thread.sleep(1000); | ||
} | ||
|
||
assertTrue(resourceContainerMXBean.getAllContainerIds().size() == 4); | ||
|
||
|
||
for (long id : resourceContainerMXBean.getAllContainerIds()) { | ||
if (id != 0) { | ||
assertTrue(resourceContainerMXBean.getConstraintsById(id).size() == 1); | ||
assertEQ(resourceContainerMXBean.getConstraintsById(id).get(0), 80L); | ||
assertGreaterThan(resourceContainerMXBean.getCPUResourceConsumedAmount(id), 0L); | ||
} else { | ||
assertTrue(resourceContainerMXBean.getConstraintsById(id).isEmpty()); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.