Skip to content

Commit

Permalink
use Time.monotonicNow
Browse files Browse the repository at this point in the history
  • Loading branch information
hfutatzhanghb committed Jan 26, 2025
1 parent c31b268 commit 594ca79
Showing 1 changed file with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.apache.hadoop.mapred.Reducer;
import org.apache.hadoop.mapred.Reporter;
import org.apache.hadoop.mapred.SequenceFileInputFormat;
import org.apache.hadoop.util.Time;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
import org.apache.hadoop.util.concurrent.HadoopExecutors;
Expand Down Expand Up @@ -97,7 +98,7 @@ public class NNBench extends Configured implements Tool {
private long numberOfMaps = 1l; // default is 1
private long numberOfReduces = 1l; // default is 1
private long startTime =
System.currentTimeMillis() + (120 * 1000); // default is 'now' + 2min
Time.monotonicNow() + (120 * 1000); // default is 'now' + 2min
private long blockSize = 1l; // default is 1
private int bytesToWrite = 0; // default is 0
private long bytesPerChecksum = 1l; // default is 1
Expand Down Expand Up @@ -709,7 +710,7 @@ public void close() throws IOException {
*/
private boolean barrier() {
long startTime = getConf().getLong("test.nnbench.starttime", 0l);
long currentTime = System.currentTimeMillis();
long currentTime = Time.monotonicNow();
long sleepTime = startTime - currentTime;
boolean retVal = true;

Expand Down Expand Up @@ -759,23 +760,23 @@ public void map(Text key,
if (barrier()) {
String fileName = "file_" + value;
if (op.equals(OP_CREATE_WRITE)) {
startTimeTPmS = System.currentTimeMillis();
startTimeTPmS = Time.monotonicNow();
doCreateWriteOp(fileName, reporter);
} else if (op.equals(OP_OPEN_READ)) {
startTimeTPmS = System.currentTimeMillis();
startTimeTPmS = Time.monotonicNow();
doOpenReadOp(fileName, reporter);
} else if (op.equals(OP_RENAME)) {
startTimeTPmS = System.currentTimeMillis();
startTimeTPmS = Time.monotonicNow();
doRenameOp(fileName, reporter);
} else if (op.equals(OP_DELETE)) {
startTimeTPmS = System.currentTimeMillis();
startTimeTPmS = Time.monotonicNow();
doDeleteOp(fileName, reporter);
} else {
throw new IllegalArgumentException(
"unsupported operation [" + op + "]");
}

endTimeTPms = System.currentTimeMillis();
endTimeTPms = Time.monotonicNow();
totalTimeTPmS = endTimeTPms - startTimeTPmS;
} else {
output.collect(new Text("l:latemaps"), new Text("1"));
Expand Down Expand Up @@ -817,7 +818,7 @@ private void doCreateWriteOp(String name,
while (! successfulOp && numOfExceptions < MAX_OPERATION_EXCEPTIONS) {
try {
// Set up timer for measuring AL (transaction #1)
startTimeAL = System.currentTimeMillis();
startTimeAL = Time.monotonicNow();
// Create the file
// Use a buffer size of 512
out = filesystem.create(filePath,
Expand All @@ -826,14 +827,14 @@ private void doCreateWriteOp(String name,
replFactor,
blkSize);
out.write(buffer);
totalTimeAL1 += (System.currentTimeMillis() - startTimeAL);
totalTimeAL1 += (Time.monotonicNow() - startTimeAL);

// Close the file / file output stream
// Set up timers for measuring AL (transaction #2)
startTimeAL = System.currentTimeMillis();
startTimeAL = Time.monotonicNow();
out.close();

totalTimeAL2 += (System.currentTimeMillis() - startTimeAL);
totalTimeAL2 += (Time.monotonicNow() - startTimeAL);
successfulOp = true;
successfulFileOps ++;

Expand Down Expand Up @@ -866,16 +867,16 @@ private void doOpenReadOp(String name,
while (! successfulOp && numOfExceptions < MAX_OPERATION_EXCEPTIONS) {
try {
// Set up timer for measuring AL
startTimeAL = System.currentTimeMillis();
startTimeAL = Time.monotonicNow();
input = filesystem.open(filePath);
totalTimeAL1 += (System.currentTimeMillis() - startTimeAL);
totalTimeAL1 += (Time.monotonicNow() - startTimeAL);

// If the file needs to be read (specified at command line)
if (readFile) {
startTimeAL = System.currentTimeMillis();
startTimeAL = Time.monotonicNow();
input.readFully(buffer);

totalTimeAL2 += (System.currentTimeMillis() - startTimeAL);
totalTimeAL2 += (Time.monotonicNow() - startTimeAL);
}
input.close();
successfulOp = true;
Expand Down Expand Up @@ -909,12 +910,12 @@ private void doRenameOp(String name,
while (! successfulOp && numOfExceptions < MAX_OPERATION_EXCEPTIONS) {
try {
// Set up timer for measuring AL
startTimeAL = System.currentTimeMillis();
startTimeAL = Time.monotonicNow();
boolean result = filesystem.rename(filePath, filePathR);
if (!result) {
throw new IOException("rename failed for " + filePath);
}
totalTimeAL1 += (System.currentTimeMillis() - startTimeAL);
totalTimeAL1 += (Time.monotonicNow() - startTimeAL);

successfulOp = true;
successfulFileOps ++;
Expand Down Expand Up @@ -945,13 +946,12 @@ private void doDeleteOp(String name,
while (! successfulOp && numOfExceptions < MAX_OPERATION_EXCEPTIONS) {
try {
// Set up timer for measuring AL
startTimeAL = System.currentTimeMillis();
startTimeAL = Time.monotonicNow();
boolean result = filesystem.delete(filePath, true);
if (!result) {
throw new IOException("delete failed for " + filePath);
}
totalTimeAL1 += (System.currentTimeMillis() - startTimeAL);

totalTimeAL1 += (Time.monotonicNow() - startTimeAL);
successfulOp = true;
successfulFileOps ++;

Expand Down

0 comments on commit 594ca79

Please sign in to comment.