YARN-2768. Avoid cloning Resource in FSAppAttempt#updateDemand. (Hong Zhiguo via kasha)

This commit is contained in:
Karthik Kambatla 2015-07-29 09:42:32 -07:00
parent 6f0a35724f
commit 5205a330b3
3 changed files with 18 additions and 3 deletions

View File

@ -378,6 +378,9 @@ Release 2.8.0 - UNRELEASED
YARN-3259. FairScheduler: Trigger fairShare updates on node events.
(Anubhav Dhoot via kasha)
YARN-2768. Avoid cloning Resource in FSAppAttempt#updateDemand.
(Hong Zhiguo via kasha)
BUG FIXES
YARN-3197. Confusing log generated by CapacityScheduler. (Varun Saxena

View File

@ -150,7 +150,19 @@ public static Resource multiplyTo(Resource lhs, double by) {
public static Resource multiply(Resource lhs, double by) {
return multiplyTo(clone(lhs), by);
}
/**
* Multiply @param rhs by @param by, and add the result to @param lhs
* without creating any new {@link Resource} object
*/
public static Resource multiplyAndAddTo(
Resource lhs, Resource rhs, double by) {
lhs.setMemory(lhs.getMemory() + (int)(rhs.getMemory() * by));
lhs.setVirtualCores(lhs.getVirtualCores()
+ (int)(rhs.getVirtualCores() * by));
return lhs;
}
public static Resource multiplyAndNormalizeUp(
ResourceCalculator calculator,Resource lhs, double by, Resource factor) {
return calculator.multiplyAndNormalizeUp(lhs, by, factor);

View File

@ -801,8 +801,8 @@ public void updateDemand() {
synchronized (this) {
for (Priority p : getPriorities()) {
for (ResourceRequest r : getResourceRequests(p).values()) {
Resource total = Resources.multiply(r.getCapability(), r.getNumContainers());
Resources.addTo(demand, total);
Resources.multiplyAndAddTo(demand,
r.getCapability(), r.getNumContainers());
}
}
}