Skip to content

Commit feae1eb

Browse files
committed
YARN-223. Update process tree instead of getting new process trees. (Radim Kolar via llu)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1424244 13f79535-47bb-0310-9956-ffa450edef68
1 parent 4208a3f commit feae1eb

File tree

13 files changed

+56
-123
lines changed

13 files changed

+56
-123
lines changed

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/Task.java

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@
6161
import org.apache.hadoop.mapreduce.MRJobConfig;
6262
import org.apache.hadoop.mapreduce.lib.reduce.WrappedReducer;
6363
import org.apache.hadoop.mapreduce.task.ReduceContextImpl;
64-
import org.apache.hadoop.yarn.util.ResourceCalculatorPlugin;
65-
import org.apache.hadoop.yarn.util.ResourceCalculatorPlugin.*;
64+
import org.apache.hadoop.yarn.util.ResourceCalculatorProcessTree;
6665
import org.apache.hadoop.net.NetUtils;
6766
import org.apache.hadoop.util.Progress;
6867
import org.apache.hadoop.util.Progressable;
@@ -169,7 +168,7 @@ static synchronized String getOutputName(int partition) {
169168
private Iterator<Long> currentRecIndexIterator =
170169
skipRanges.skipRangeIterator();
171170

172-
private ResourceCalculatorPlugin resourceCalculator = null;
171+
private ResourceCalculatorProcessTree pTree;
173172
private long initCpuCumulativeTime = 0;
174173

175174
protected JobConf conf;
@@ -372,7 +371,7 @@ public void setSkipping(boolean skipping) {
372371
* Return current state of the task.
373372
* needs to be synchronized as communication thread
374373
* sends the state every second
375-
* @return
374+
* @return task state
376375
*/
377376
synchronized TaskStatus.State getState(){
378377
return this.taskStatus.getRunState();
@@ -558,15 +557,15 @@ public void initialize(JobConf job, JobID id,
558557
}
559558
}
560559
committer.setupTask(taskContext);
561-
Class<? extends ResourceCalculatorPlugin> clazz =
562-
conf.getClass(MRConfig.RESOURCE_CALCULATOR_PLUGIN,
563-
null, ResourceCalculatorPlugin.class);
564-
resourceCalculator = ResourceCalculatorPlugin
565-
.getResourceCalculatorPlugin(clazz, conf);
566-
LOG.info(" Using ResourceCalculatorPlugin : " + resourceCalculator);
567-
if (resourceCalculator != null) {
568-
initCpuCumulativeTime =
569-
resourceCalculator.getProcResourceValues().getCumulativeCpuTime();
560+
Class<? extends ResourceCalculatorProcessTree> clazz =
561+
conf.getClass(MRConfig.RESOURCE_CALCULATOR_PROCESS_TREE,
562+
null, ResourceCalculatorProcessTree.class);
563+
pTree = ResourceCalculatorProcessTree
564+
.getResourceCalculatorProcessTree(System.getenv().get("JVM_PID"), clazz, conf);
565+
LOG.info(" Using ResourceCalculatorProcessTree : " + pTree);
566+
if (pTree != null) {
567+
pTree.updateProcessTree();
568+
initCpuCumulativeTime = pTree.getCumulativeCpuTime();
570569
}
571570
}
572571

@@ -817,14 +816,14 @@ void updateResourceCounters() {
817816
// Update generic resource counters
818817
updateHeapUsageCounter();
819818

820-
// Updating resources specified in ResourceCalculatorPlugin
821-
if (resourceCalculator == null) {
819+
// Updating resources specified in ResourceCalculatorProcessTree
820+
if (pTree == null) {
822821
return;
823822
}
824-
ProcResourceValues res = resourceCalculator.getProcResourceValues();
825-
long cpuTime = res.getCumulativeCpuTime();
826-
long pMem = res.getPhysicalMemorySize();
827-
long vMem = res.getVirtualMemorySize();
823+
pTree.updateProcessTree();
824+
long cpuTime = pTree.getCumulativeCpuTime();
825+
long pMem = pTree.getCumulativeRssmem();
826+
long vMem = pTree.getCumulativeVmem();
828827
// Remove the CPU time consumed previously by JVM reuse
829828
cpuTime -= initCpuCumulativeTime;
830829
counters.findCounter(TaskCounter.CPU_MILLISECONDS).setValue(cpuTime);

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/MRConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ public interface MRConfig {
5555
public static final long DELEGATION_TOKEN_MAX_LIFETIME_DEFAULT =
5656
7*24*60*60*1000; // 7 days
5757

58-
public static final String RESOURCE_CALCULATOR_PLUGIN =
59-
"mapreduce.job.resourcecalculatorplugin";
58+
public static final String RESOURCE_CALCULATOR_PROCESS_TREE =
59+
"mapreduce.job.process-tree.class";
6060
public static final String STATIC_RESOLUTIONS =
6161
"mapreduce.job.net.static.resolutions";
6262

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/util/LinuxResourceCalculatorPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ public static void main(String[] args) {
409409

410410
@Override
411411
public ProcResourceValues getProcResourceValues() {
412-
pTree = pTree.getProcessTree();
412+
pTree.updateProcessTree();
413413
long cpuTime = pTree.getCumulativeCpuTime();
414414
long pMem = pTree.getCumulativeRssmem();
415415
long vMem = pTree.getCumulativeVmem();

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/util/ProcfsBasedProcessTree.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,10 @@ public static boolean isAvailable() {
166166
}
167167

168168
/**
169-
* Get the process-tree with latest state. If the root-process is not alive,
170-
* an empty tree will be returned.
171-
*
172-
* @return the process-tree with latest state.
169+
* Update the process-tree with latest state. If the root-process is not alive,
170+
* tree will become empty.
173171
*/
174-
public ProcfsBasedProcessTree getProcessTree() {
172+
public void updateProcessTree() {
175173
if (!pid.equals(deadPid)) {
176174
// Get the list of processes
177175
List<String> processList = getProcessList();
@@ -197,7 +195,7 @@ public ProcfsBasedProcessTree getProcessTree() {
197195
}
198196

199197
if (me == null) {
200-
return this;
198+
return;
201199
}
202200

203201
// Add each process to its parent.
@@ -239,7 +237,6 @@ public ProcfsBasedProcessTree getProcessTree() {
239237
LOG.debug(this.toString());
240238
}
241239
}
242-
return this;
243240
}
244241

245242
/**

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/util/TestProcfsBasedProcessTree.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public void testProcessTree() {
151151
ProcfsBasedProcessTree p = new ProcfsBasedProcessTree(pid,
152152
ProcessTree.isSetsidAvailable,
153153
ProcessTree.DEFAULT_SLEEPTIME_BEFORE_SIGKILL);
154-
p = p.getProcessTree(); // initialize
154+
p.updateProcessTree(); // initialize
155155
LOG.info("ProcessTree: " + p.toString());
156156

157157
File leaf = new File(lowestDescendant);
@@ -164,7 +164,7 @@ public void testProcessTree() {
164164
}
165165
}
166166

167-
p = p.getProcessTree(); // reconstruct
167+
p.updateProcessTree(); // reconstruct
168168
LOG.info("ProcessTree: " + p.toString());
169169

170170
// Get the process-tree dump
@@ -203,7 +203,7 @@ public void testProcessTree() {
203203
}
204204

205205
// ProcessTree is gone now. Any further calls should be sane.
206-
p = p.getProcessTree();
206+
p.updateProcessTree();
207207
assertFalse("ProcessTree must have been gone", p.isAlive());
208208
assertTrue("Cumulative vmem for the gone-process is "
209209
+ p.getCumulativeVmem() + " . It should be zero.", p
@@ -336,7 +336,7 @@ public void testCpuAndMemoryForProcessTree() throws IOException {
336336
new ProcfsBasedProcessTree("100", true, 100L,
337337
procfsRootDir.getAbsolutePath());
338338
// build the process tree.
339-
processTree.getProcessTree();
339+
processTree.updateProcessTree();
340340

341341
// verify cumulative memory
342342
assertEquals("Cumulative virtual memory does not match", 600000L,
@@ -362,7 +362,7 @@ public void testCpuAndMemoryForProcessTree() throws IOException {
362362
writeStatFiles(procfsRootDir, pids, procInfos);
363363

364364
// build the process tree.
365-
processTree.getProcessTree();
365+
processTree.updateProcessTree();
366366

367367
// verify cumulative cpu time again
368368
cumuCpuTime = ProcfsBasedProcessTree.JIFFY_LENGTH_IN_MILLIS > 0 ?
@@ -409,7 +409,7 @@ public void testMemForOlderProcesses() throws IOException {
409409
new ProcfsBasedProcessTree("100", true, 100L,
410410
procfsRootDir.getAbsolutePath());
411411
// build the process tree.
412-
processTree.getProcessTree();
412+
processTree.updateProcessTree();
413413

414414
// verify cumulative memory
415415
assertEquals("Cumulative memory does not match",
@@ -425,7 +425,7 @@ public void testMemForOlderProcesses() throws IOException {
425425
writeStatFiles(procfsRootDir, newPids, newProcInfos);
426426

427427
// check memory includes the new process.
428-
processTree.getProcessTree();
428+
processTree.updateProcessTree();
429429
assertEquals("Cumulative vmem does not include new process",
430430
1200000L, processTree.getCumulativeVmem());
431431
long cumuRssMem = ProcfsBasedProcessTree.PAGE_SIZE > 0 ?
@@ -451,7 +451,7 @@ public void testMemForOlderProcesses() throws IOException {
451451
writeStatFiles(procfsRootDir, newPids, newProcInfos);
452452

453453
// refresh process tree
454-
processTree.getProcessTree();
454+
processTree.updateProcessTree();
455455

456456
// processes older than 2 iterations should be same as before.
457457
assertEquals("Cumulative vmem shouldn't have included new processes",
@@ -555,7 +555,7 @@ public void testProcessTreeDump()
555555
new ProcfsBasedProcessTree("100", true, 100L, procfsRootDir
556556
.getAbsolutePath());
557557
// build the process tree.
558-
processTree.getProcessTree();
558+
processTree.updateProcessTree();
559559

560560
// Get the process-tree dump
561561
String processTreeDump = processTree.getProcessTreeDump();

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/LinuxResourceCalculatorPlugin.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ public class LinuxResourceCalculatorPlugin extends ResourceCalculatorPlugin {
9191
private float cpuUsage = UNAVAILABLE;
9292
private long sampleTime = UNAVAILABLE;
9393
private long lastSampleTime = UNAVAILABLE;
94-
private ResourceCalculatorProcessTree pTree = null;
9594

9695
boolean readMemInfoFile = false;
9796
boolean readCpuInfoFile = false;
@@ -109,8 +108,6 @@ public LinuxResourceCalculatorPlugin() {
109108
procfsCpuFile = PROCFS_CPUINFO;
110109
procfsStatFile = PROCFS_STAT;
111110
jiffyLengthInMillis = ProcfsBasedProcessTree.JIFFY_LENGTH_IN_MILLIS;
112-
String pid = System.getenv().get("JVM_PID");
113-
pTree = new ProcfsBasedProcessTree(pid);
114111
}
115112

116113
/**
@@ -129,8 +126,6 @@ public LinuxResourceCalculatorPlugin(String procfsMemFile,
129126
this.procfsCpuFile = procfsCpuFile;
130127
this.procfsStatFile = procfsStatFile;
131128
this.jiffyLengthInMillis = jiffyLengthInMillis;
132-
String pid = System.getenv().get("JVM_PID");
133-
pTree = new ProcfsBasedProcessTree(pid);
134129
}
135130

136131
/**
@@ -400,13 +395,4 @@ public static void main(String[] args) {
400395
}
401396
System.out.println("CPU usage % : " + plugin.getCpuUsage());
402397
}
403-
404-
@Override
405-
public ProcResourceValues getProcResourceValues() {
406-
pTree = pTree.getProcessTree();
407-
long cpuTime = pTree.getCumulativeCpuTime();
408-
long pMem = pTree.getCumulativeRssmem();
409-
long vMem = pTree.getCumulativeVmem();
410-
return new ProcResourceValues(cpuTime, pMem, vMem);
411-
}
412398
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/ProcfsBasedProcessTree.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,12 @@ public static boolean isAvailable() {
140140
}
141141

142142
/**
143-
* Get the process-tree with latest state. If the root-process is not alive,
144-
* an empty tree will be returned.
143+
* Update process-tree with latest state. If the root-process is not alive,
144+
* tree will be empty.
145145
*
146-
* @return the process-tree with latest state.
147146
*/
148147
@Override
149-
public ResourceCalculatorProcessTree getProcessTree() {
148+
public void updateProcessTree() {
150149
if (!pid.equals(deadPid)) {
151150
// Get the list of processes
152151
List<String> processList = getProcessList();
@@ -172,7 +171,7 @@ public ResourceCalculatorProcessTree getProcessTree() {
172171
}
173172

174173
if (me == null) {
175-
return this;
174+
return;
176175
}
177176

178177
// Add each process to its parent.
@@ -214,7 +213,6 @@ public ResourceCalculatorProcessTree getProcessTree() {
214213
LOG.debug(this.toString());
215214
}
216215
}
217-
return this;
218216
}
219217

220218
/** Verify that the given process id is same as its process group id.

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/ResourceCalculatorPlugin.java

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -90,48 +90,6 @@ public abstract class ResourceCalculatorPlugin extends Configured {
9090
*/
9191
public abstract float getCpuUsage();
9292

93-
/**
94-
* Obtain resource status used by current process tree.
95-
*/
96-
@InterfaceAudience.Private
97-
@InterfaceStability.Unstable
98-
public abstract ProcResourceValues getProcResourceValues();
99-
100-
public static class ProcResourceValues {
101-
private final long cumulativeCpuTime;
102-
private final long physicalMemorySize;
103-
private final long virtualMemorySize;
104-
public ProcResourceValues(long cumulativeCpuTime, long physicalMemorySize,
105-
long virtualMemorySize) {
106-
this.cumulativeCpuTime = cumulativeCpuTime;
107-
this.physicalMemorySize = physicalMemorySize;
108-
this.virtualMemorySize = virtualMemorySize;
109-
}
110-
/**
111-
* Obtain the physical memory size used by current process tree.
112-
* @return physical memory size in bytes.
113-
*/
114-
public long getPhysicalMemorySize() {
115-
return physicalMemorySize;
116-
}
117-
118-
/**
119-
* Obtain the virtual memory size used by a current process tree.
120-
* @return virtual memory size in bytes.
121-
*/
122-
public long getVirtualMemorySize() {
123-
return virtualMemorySize;
124-
}
125-
126-
/**
127-
* Obtain the cumulative CPU time used by a current process tree.
128-
* @return cumulative CPU time in milliseconds
129-
*/
130-
public long getCumulativeCpuTime() {
131-
return cumulativeCpuTime;
132-
}
133-
}
134-
13593
/**
13694
* Create the ResourceCalculatorPlugin from the class name and configure it. If
13795
* class name is null, this method will try and return a memory calculator

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/ResourceCalculatorProcessTree.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,14 @@ public ResourceCalculatorProcessTree(String root) {
4343
}
4444

4545
/**
46-
* Get the process-tree with latest state. If the root-process is not alive,
47-
* an empty tree will be returned.
46+
* Update the process-tree with latest state.
4847
*
4948
* Each call to this function should increment the age of the running
5049
* processes that already exist in the process tree. Age is used other API's
5150
* of the interface.
5251
*
53-
* @return the process-tree with latest state.
5452
*/
55-
public abstract ResourceCalculatorProcessTree getProcessTree();
53+
public abstract void updateProcessTree();
5654

5755
/**
5856
* Get a dump of the process-tree.

0 commit comments

Comments
 (0)