Skip to content

Commit ce93595

Browse files
committed
MAPREDUCE-6729. Accurately compute the test execute time in DFSIO. Contributed by mingleizhang.
This closes #112
1 parent 8d32bd8 commit ce93595

File tree

1 file changed

+27
-27
lines changed
  • hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/fs

1 file changed

+27
-27
lines changed

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/fs/TestDFSIO.java

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -228,67 +228,53 @@ public static void afterClass() throws Exception {
228228

229229
public static void testWrite() throws Exception {
230230
FileSystem fs = cluster.getFileSystem();
231-
long tStart = System.currentTimeMillis();
232-
bench.writeTest(fs);
233-
long execTime = System.currentTimeMillis() - tStart;
231+
long execTime = bench.writeTest(fs);
234232
bench.analyzeResult(fs, TestType.TEST_TYPE_WRITE, execTime);
235233
}
236234

237235
@Test (timeout = 10000)
238236
public void testRead() throws Exception {
239237
FileSystem fs = cluster.getFileSystem();
240-
long tStart = System.currentTimeMillis();
241-
bench.readTest(fs);
242-
long execTime = System.currentTimeMillis() - tStart;
238+
long execTime = bench.readTest(fs);
243239
bench.analyzeResult(fs, TestType.TEST_TYPE_READ, execTime);
244240
}
245241

246242
@Test (timeout = 10000)
247243
public void testReadRandom() throws Exception {
248244
FileSystem fs = cluster.getFileSystem();
249-
long tStart = System.currentTimeMillis();
250245
bench.getConf().setLong("test.io.skip.size", 0);
251-
bench.randomReadTest(fs);
252-
long execTime = System.currentTimeMillis() - tStart;
246+
long execTime = bench.randomReadTest(fs);
253247
bench.analyzeResult(fs, TestType.TEST_TYPE_READ_RANDOM, execTime);
254248
}
255249

256250
@Test (timeout = 10000)
257251
public void testReadBackward() throws Exception {
258252
FileSystem fs = cluster.getFileSystem();
259-
long tStart = System.currentTimeMillis();
260253
bench.getConf().setLong("test.io.skip.size", -DEFAULT_BUFFER_SIZE);
261-
bench.randomReadTest(fs);
262-
long execTime = System.currentTimeMillis() - tStart;
254+
long execTime = bench.randomReadTest(fs);
263255
bench.analyzeResult(fs, TestType.TEST_TYPE_READ_BACKWARD, execTime);
264256
}
265257

266258
@Test (timeout = 10000)
267259
public void testReadSkip() throws Exception {
268260
FileSystem fs = cluster.getFileSystem();
269-
long tStart = System.currentTimeMillis();
270261
bench.getConf().setLong("test.io.skip.size", 1);
271-
bench.randomReadTest(fs);
272-
long execTime = System.currentTimeMillis() - tStart;
262+
long execTime = bench.randomReadTest(fs);
273263
bench.analyzeResult(fs, TestType.TEST_TYPE_READ_SKIP, execTime);
274264
}
275265

276266
@Test (timeout = 10000)
277267
public void testAppend() throws Exception {
278268
FileSystem fs = cluster.getFileSystem();
279-
long tStart = System.currentTimeMillis();
280-
bench.appendTest(fs);
281-
long execTime = System.currentTimeMillis() - tStart;
269+
long execTime = bench.appendTest(fs);
282270
bench.analyzeResult(fs, TestType.TEST_TYPE_APPEND, execTime);
283271
}
284272

285273
@Test (timeout = 60000)
286274
public void testTruncate() throws Exception {
287275
FileSystem fs = cluster.getFileSystem();
288276
bench.createControlFile(fs, DEFAULT_NR_BYTES / 2, DEFAULT_NR_FILES);
289-
long tStart = System.currentTimeMillis();
290-
bench.truncateTest(fs);
291-
long execTime = System.currentTimeMillis() - tStart;
277+
long execTime = bench.truncateTest(fs);
292278
bench.analyzeResult(fs, TestType.TEST_TYPE_TRUNCATE, execTime);
293279
}
294280

@@ -430,12 +416,14 @@ public Long doIO(Reporter reporter,
430416
}
431417
}
432418

433-
private void writeTest(FileSystem fs) throws IOException {
419+
private long writeTest(FileSystem fs) throws IOException {
434420
Path writeDir = getWriteDir(config);
435421
fs.delete(getDataDir(config), true);
436422
fs.delete(writeDir, true);
437-
423+
long tStart = System.currentTimeMillis();
438424
runIOTest(WriteMapper.class, writeDir);
425+
long execTime = System.currentTimeMillis() - tStart;
426+
return execTime;
439427
}
440428

441429
private void runIOTest(
@@ -496,10 +484,13 @@ public Long doIO(Reporter reporter,
496484
}
497485
}
498486

499-
private void appendTest(FileSystem fs) throws IOException {
487+
private long appendTest(FileSystem fs) throws IOException {
500488
Path appendDir = getAppendDir(config);
501489
fs.delete(appendDir, true);
490+
long tStart = System.currentTimeMillis();
502491
runIOTest(AppendMapper.class, appendDir);
492+
long execTime = System.currentTimeMillis() - tStart;
493+
return execTime;
503494
}
504495

505496
/**
@@ -539,10 +530,13 @@ public Long doIO(Reporter reporter,
539530
}
540531
}
541532

542-
private void readTest(FileSystem fs) throws IOException {
533+
private long readTest(FileSystem fs) throws IOException {
543534
Path readDir = getReadDir(config);
544535
fs.delete(readDir, true);
536+
long tStart = System.currentTimeMillis();
545537
runIOTest(ReadMapper.class, readDir);
538+
long execTime = System.currentTimeMillis() - tStart;
539+
return execTime;
546540
}
547541

548542
/**
@@ -620,10 +614,13 @@ private long nextOffset(long current) {
620614
}
621615
}
622616

623-
private void randomReadTest(FileSystem fs) throws IOException {
617+
private long randomReadTest(FileSystem fs) throws IOException {
624618
Path readDir = getRandomReadDir(config);
625619
fs.delete(readDir, true);
620+
long tStart = System.currentTimeMillis();
626621
runIOTest(RandomReadMapper.class, readDir);
622+
long execTime = System.currentTimeMillis() - tStart;
623+
return execTime;
627624
}
628625

629626
/**
@@ -665,10 +662,13 @@ public Long doIO(Reporter reporter,
665662
}
666663
}
667664

668-
private void truncateTest(FileSystem fs) throws IOException {
665+
private long truncateTest(FileSystem fs) throws IOException {
669666
Path TruncateDir = getTruncateDir(config);
670667
fs.delete(TruncateDir, true);
668+
long tStart = System.currentTimeMillis();
671669
runIOTest(TruncateMapper.class, TruncateDir);
670+
long execTime = System.currentTimeMillis() - tStart;
671+
return execTime;
672672
}
673673

674674
private void sequentialTest(FileSystem fs,

0 commit comments

Comments
 (0)