YARN-5242. Update DominantResourceCalculator to consider all resource types in calculations. Contributed by Varun Vasudev.
This commit is contained in:
parent
759114b006
commit
9e4ba6aff5
|
@ -327,6 +327,8 @@ public abstract class Resource implements Comparable<Resource> {
|
||||||
otherResources = other.getResources();
|
otherResources = other.getResources();
|
||||||
long diff = thisResources.size() - otherResources.size();
|
long diff = thisResources.size() - otherResources.size();
|
||||||
if (diff == 0) {
|
if (diff == 0) {
|
||||||
|
// compare memory and vcores first(in that order) to preserve
|
||||||
|
// existing behaviour
|
||||||
if (thisResources.keySet().equals(otherResources.keySet())) {
|
if (thisResources.keySet().equals(otherResources.keySet())) {
|
||||||
diff = this.getMemorySize() - other.getMemorySize();
|
diff = this.getMemorySize() - other.getMemorySize();
|
||||||
if (diff == 0) {
|
if (diff == 0) {
|
||||||
|
@ -335,6 +337,11 @@ public abstract class Resource implements Comparable<Resource> {
|
||||||
if (diff == 0) {
|
if (diff == 0) {
|
||||||
for (Map.Entry<String, ResourceInformation> entry : thisResources
|
for (Map.Entry<String, ResourceInformation> entry : thisResources
|
||||||
.entrySet()) {
|
.entrySet()) {
|
||||||
|
if (entry.getKey().equals(ResourceInformation.MEMORY_MB.getName())
|
||||||
|
|| entry.getKey()
|
||||||
|
.equals(ResourceInformation.VCORES.getName())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
diff =
|
diff =
|
||||||
entry.getValue().compareTo(otherResources.get(entry.getKey()));
|
entry.getValue().compareTo(otherResources.get(entry.getKey()));
|
||||||
if (diff != 0) {
|
if (diff != 0) {
|
||||||
|
|
|
@ -242,7 +242,7 @@ public class ResourcePBImpl extends Resource {
|
||||||
builder.addResourceValueMap(e);
|
builder.addResourceValueMap(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
builder.setMemory(this.getMemory());
|
builder.setMemory(this.getMemorySize());
|
||||||
builder.setVirtualCores(this.getVirtualCores());
|
builder.setVirtualCores(this.getVirtualCores());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -397,10 +397,25 @@ public class DominantResourceCalculator extends ResourceCalculator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean fitsIn(Resource cluster,
|
public boolean fitsIn(Resource cluster, Resource smaller, Resource bigger) {
|
||||||
Resource smaller, Resource bigger) {
|
for (String resource : resourceNames) {
|
||||||
return smaller.getMemorySize() <= bigger.getMemorySize()
|
try {
|
||||||
&& smaller.getVirtualCores() <= bigger.getVirtualCores();
|
ResourceInformation sResourceInformation =
|
||||||
|
smaller.getResourceInformation(resource);
|
||||||
|
ResourceInformation bResourceInformation =
|
||||||
|
bigger.getResourceInformation(resource);
|
||||||
|
Long sResourceValue = UnitsConversionUtil
|
||||||
|
.convert(sResourceInformation.getUnits(),
|
||||||
|
bResourceInformation.getUnits(),
|
||||||
|
sResourceInformation.getValue());
|
||||||
|
if(sResourceValue > bResourceInformation.getValue()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} catch (YarnException ye) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -178,7 +178,6 @@ public class ResourceUtils {
|
||||||
synchronized (ResourceUtils.class) {
|
synchronized (ResourceUtils.class) {
|
||||||
if (lock == null) {
|
if (lock == null) {
|
||||||
synchronized (ResourceUtils.class) {
|
synchronized (ResourceUtils.class) {
|
||||||
lock = new Object();
|
|
||||||
Map<String, ResourceInformation> resources = new HashMap<>();
|
Map<String, ResourceInformation> resources = new HashMap<>();
|
||||||
if (conf == null) {
|
if (conf == null) {
|
||||||
conf = new YarnConfiguration();
|
conf = new YarnConfiguration();
|
||||||
|
@ -187,10 +186,12 @@ public class ResourceUtils {
|
||||||
addResourcesFileToConf(resourceFile, conf);
|
addResourcesFileToConf(resourceFile, conf);
|
||||||
LOG.debug("Found " + resourceFile + ", adding to configuration");
|
LOG.debug("Found " + resourceFile + ", adding to configuration");
|
||||||
initializeResourcesMap(conf, resources);
|
initializeResourcesMap(conf, resources);
|
||||||
|
lock = new Object();
|
||||||
} catch (FileNotFoundException fe) {
|
} catch (FileNotFoundException fe) {
|
||||||
LOG.info("Unable to find '" + resourceFile
|
LOG.info("Unable to find '" + resourceFile
|
||||||
+ "'. Falling back to memory and vcores as resources", fe);
|
+ "'. Falling back to memory and vcores as resources", fe);
|
||||||
initializeResourcesMap(conf, resources);
|
initializeResourcesMap(conf, resources);
|
||||||
|
lock = new Object();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -268,12 +269,12 @@ public class ResourceUtils {
|
||||||
synchronized (ResourceUtils.class) {
|
synchronized (ResourceUtils.class) {
|
||||||
if (nodeLock == null) {
|
if (nodeLock == null) {
|
||||||
synchronized (ResourceUtils.class) {
|
synchronized (ResourceUtils.class) {
|
||||||
nodeLock = new Object();
|
|
||||||
Map<String, ResourceInformation> nodeResources =
|
Map<String, ResourceInformation> nodeResources =
|
||||||
initializeNodeResourceInformation(conf);
|
initializeNodeResourceInformation(conf);
|
||||||
addManadtoryResources(nodeResources);
|
addManadtoryResources(nodeResources);
|
||||||
checkMandatatoryResources(nodeResources);
|
checkMandatatoryResources(nodeResources);
|
||||||
readOnlyNodeResources = Collections.unmodifiableMap(nodeResources);
|
readOnlyNodeResources = Collections.unmodifiableMap(nodeResources);
|
||||||
|
nodeLock = new Object();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,16 +134,12 @@ public class Resources {
|
||||||
|
|
||||||
private Map<String, ResourceInformation> initResourceMap() {
|
private Map<String, ResourceInformation> initResourceMap() {
|
||||||
Map<String, ResourceInformation> tmp = new HashMap<>();
|
Map<String, ResourceInformation> tmp = new HashMap<>();
|
||||||
// Due to backwards compat, the max value for memory and vcores
|
|
||||||
// needs to be Integer.MAX_VALUE
|
|
||||||
int max = resourceValue > Integer.MAX_VALUE ? Integer.MAX_VALUE :
|
|
||||||
resourceValue.intValue();
|
|
||||||
Map<String, ResourceInformation> types = ResourceUtils.getResourceTypes();
|
Map<String, ResourceInformation> types = ResourceUtils.getResourceTypes();
|
||||||
if (types != null) {
|
if (types != null) {
|
||||||
for (Map.Entry<String, ResourceInformation> entry : types.entrySet()) {
|
for (Map.Entry<String, ResourceInformation> entry : types.entrySet()) {
|
||||||
tmp.put(entry.getKey(),
|
tmp.put(entry.getKey(),
|
||||||
ResourceInformation.newInstance(entry.getValue()));
|
ResourceInformation.newInstance(entry.getValue()));
|
||||||
tmp.get(entry.getKey()).setValue((long) max);
|
tmp.get(entry.getKey()).setValue(resourceValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tmp;
|
return tmp;
|
||||||
|
|
Loading…
Reference in New Issue