[feature-wip](resouce-group) Supports memory soft isolation of resource group (#19802)

create resource groups name properties(
    'enable_memory_overcommit' = 'true' // whether to enable memory soft isolation
)
This commit is contained in:
luozenglin
2023-05-21 19:33:57 +08:00
committed by GitHub
parent a7f3bfec89
commit 33fd965b5c
11 changed files with 167 additions and 48 deletions

View File

@ -46,11 +46,13 @@ public class ResourceGroup implements Writable {
public static final String MEMORY_LIMIT = "memory_limit";
public static final String ENABLE_MEMORY_OVERCOMMIT = "enable_memory_overcommit";
private static final ImmutableSet<String> REQUIRED_PROPERTIES_NAME = new ImmutableSet.Builder<String>().add(
CPU_SHARE).add(MEMORY_LIMIT).build();
private static final ImmutableSet<String> ALL_PROPERTIES_NAME = new ImmutableSet.Builder<String>().add(
CPU_SHARE).add(MEMORY_LIMIT).build();
CPU_SHARE).add(MEMORY_LIMIT).add(ENABLE_MEMORY_OVERCOMMIT).build();
@SerializedName(value = "id")
private long id;
@ -78,6 +80,9 @@ public class ResourceGroup implements Writable {
this.version = version;
String memoryLimitString = properties.get(MEMORY_LIMIT);
this.memoryLimitPercent = Double.parseDouble(memoryLimitString.substring(0, memoryLimitString.length() - 1));
if (properties.containsKey(ENABLE_MEMORY_OVERCOMMIT)) {
properties.put(ENABLE_MEMORY_OVERCOMMIT, properties.get(ENABLE_MEMORY_OVERCOMMIT).toLowerCase());
}
}
public static ResourceGroup create(String name, Map<String, String> properties) throws DdlException {
@ -129,6 +134,13 @@ public class ResourceGroup implements Writable {
LOG.debug(memLimitErr, e);
throw new DdlException(memLimitErr);
}
if (properties.containsKey(ENABLE_MEMORY_OVERCOMMIT)) {
String value = properties.get(ENABLE_MEMORY_OVERCOMMIT).toLowerCase();
if (!("true".equals(value) || "false".equals(value))) {
throw new DdlException("The value of '" + ENABLE_MEMORY_OVERCOMMIT + "' must be true or false.");
}
}
}
public long getId() {

View File

@ -123,7 +123,8 @@ public class ResourceGroupMgr implements Writable, GsonPostProcessable {
}
Map<String, String> properties = Maps.newHashMap();
properties.put(ResourceGroup.CPU_SHARE, "10");
properties.put(ResourceGroup.MEMORY_LIMIT, "100%");
properties.put(ResourceGroup.MEMORY_LIMIT, "30%");
properties.put(ResourceGroup.ENABLE_MEMORY_OVERCOMMIT, "true");
defaultResourceGroup = ResourceGroup.create(DEFAULT_GROUP_NAME, properties);
nameToResourceGroup.put(DEFAULT_GROUP_NAME, defaultResourceGroup);
idToResourceGroup.put(defaultResourceGroup.getId(), defaultResourceGroup);