|
@@ -19,10 +19,12 @@
|
|
|
package org.apache.hadoop.fs.loadGenerator;
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
-import java.io.File;
|
|
|
-import java.io.FileReader;
|
|
|
+import java.io.DataInputStream;
|
|
|
+import java.io.FileNotFoundException;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
+import java.io.InputStreamReader;
|
|
|
+import java.io.PrintStream;
|
|
|
import java.net.InetAddress;
|
|
|
import java.net.UnknownHostException;
|
|
|
import java.util.ArrayList;
|
|
@@ -36,10 +38,11 @@ import org.apache.hadoop.conf.Configuration;
|
|
|
import org.apache.hadoop.conf.Configured;
|
|
|
import org.apache.hadoop.fs.CreateFlag;
|
|
|
import org.apache.hadoop.fs.FSDataOutputStream;
|
|
|
-import org.apache.hadoop.fs.FileStatus;
|
|
|
import org.apache.hadoop.fs.FileContext;
|
|
|
-import org.apache.hadoop.fs.Path;
|
|
|
+import org.apache.hadoop.fs.FileStatus;
|
|
|
import org.apache.hadoop.fs.Options.CreateOpts;
|
|
|
+import org.apache.hadoop.fs.Path;
|
|
|
+import org.apache.hadoop.fs.UnsupportedFileSystemException;
|
|
|
import org.apache.hadoop.io.IOUtils;
|
|
|
import org.apache.hadoop.util.Time;
|
|
|
import org.apache.hadoop.util.Tool;
|
|
@@ -48,8 +51,11 @@ import org.apache.hadoop.util.ToolRunner;
|
|
|
import com.google.common.base.Preconditions;
|
|
|
|
|
|
/** The load generator is a tool for testing NameNode behavior under
|
|
|
- * different client loads.
|
|
|
- * It allows the user to generate different mixes of read, write,
|
|
|
+ * different client loads. Note there is a subclass of this clas that lets
|
|
|
+ * you run a the load generator as a MapReduce job (see LoadGeneratorMR in the
|
|
|
+ * MapReduce project.
|
|
|
+ *
|
|
|
+ * The loadGenerator allows the user to generate different mixes of read, write,
|
|
|
* and list requests by specifying the probabilities of read and
|
|
|
* write. The user controls the intensity of the load by
|
|
|
* adjusting parameters for the number of worker threads and the delay
|
|
@@ -58,15 +64,24 @@ import com.google.common.base.Preconditions;
|
|
|
* generator exits, it print some NameNode statistics like the average
|
|
|
* execution time of each kind of operations and the NameNode
|
|
|
* throughput.
|
|
|
+ *
|
|
|
+ * The program can run in one of two forms. As a regular single process command
|
|
|
+ * that runs multiple threads to generate load on the NN or as a Map Reduce
|
|
|
+ * program that runs multiple (multi-threaded) map tasks that generate load
|
|
|
+ * on the NN; the results summary is generated by a single reduce task.
|
|
|
+ *
|
|
|
*
|
|
|
* The user may either specify constant duration, read and write
|
|
|
* probabilities via the command line, or may specify a text file
|
|
|
* that acts as a script of which read and write probabilities to
|
|
|
- * use for specified durations.
|
|
|
+ * use for specified durations. If no duration is specified the program
|
|
|
+ * runs till killed (duration required if run as MapReduce).
|
|
|
*
|
|
|
* The script takes the form of lines of duration in seconds, read
|
|
|
* probability and write probability, each separated by white space.
|
|
|
- * Blank lines and lines starting with # (comments) are ignored.
|
|
|
+ * Blank lines and lines starting with # (comments) are ignored. If load
|
|
|
+ * generator is run as a MapReduce program then the script file needs to be
|
|
|
+ * accessible on the the Map task as a HDFS file.
|
|
|
*
|
|
|
* After command line argument parsing and data initialization,
|
|
|
* the load generator spawns the number of worker threads
|
|
@@ -116,31 +131,43 @@ import com.google.common.base.Preconditions;
|
|
|
public class LoadGenerator extends Configured implements Tool {
|
|
|
public static final Log LOG = LogFactory.getLog(LoadGenerator.class);
|
|
|
|
|
|
- private volatile boolean shouldRun = true;
|
|
|
- private Path root = DataGenerator.DEFAULT_ROOT;
|
|
|
- private FileContext fc;
|
|
|
- private int maxDelayBetweenOps = 0;
|
|
|
- private int numOfThreads = 200;
|
|
|
- private long [] durations = {0};
|
|
|
- private double [] readProbs = {0.3333};
|
|
|
- private double [] writeProbs = {0.3333};
|
|
|
- private volatile int currentIndex = 0;
|
|
|
- long totalTime = 0;
|
|
|
- private long startTime = Time.now()+10000;
|
|
|
+ private volatile static boolean shouldRun = true;
|
|
|
+ protected static Path root = DataGenerator.DEFAULT_ROOT;
|
|
|
+ private static FileContext fc;
|
|
|
+ protected static int maxDelayBetweenOps = 0;
|
|
|
+ protected static int numOfThreads = 200;
|
|
|
+ protected static long [] durations = {0};
|
|
|
+ protected static double [] readProbs = {0.3333};
|
|
|
+ protected static double [] writeProbs = {0.3333};
|
|
|
+ private static volatile int currentIndex = 0;
|
|
|
+ protected static long totalTime = 0;
|
|
|
+ protected static long startTime = Time.now()+10000;
|
|
|
final static private int BLOCK_SIZE = 10;
|
|
|
- private ArrayList<String> files = new ArrayList<String>(); // a table of file names
|
|
|
- private ArrayList<String> dirs = new ArrayList<String>(); // a table of directory names
|
|
|
- private Random r = null;
|
|
|
- final private static String USAGE = "java LoadGenerator\n" +
|
|
|
- "-readProbability <read probability>\n" +
|
|
|
- "-writeProbability <write probability>\n" +
|
|
|
- "-root <root>\n" +
|
|
|
- "-maxDelayBetweenOps <maxDelayBetweenOpsInMillis>\n" +
|
|
|
- "-numOfThreads <numOfThreads>\n" +
|
|
|
- "-elapsedTime <elapsedTimeInSecs>\n" +
|
|
|
- "-startTime <startTimeInMillis>\n" +
|
|
|
- "-scriptFile <filename>";
|
|
|
- final private String hostname;
|
|
|
+ private static ArrayList<String> files = new ArrayList<String>(); // a table of file names
|
|
|
+ private static ArrayList<String> dirs = new ArrayList<String>(); // a table of directory names
|
|
|
+ protected static Random r = null;
|
|
|
+ protected static long seed = 0;
|
|
|
+ protected static String scriptFile = null;
|
|
|
+ protected static final String FLAGFILE_DEFAULT = "/tmp/flagFile";
|
|
|
+ protected static Path flagFile = new Path(FLAGFILE_DEFAULT);
|
|
|
+ protected String hostname;
|
|
|
+ final private static String USAGE_CMD = "java LoadGenerator\n";
|
|
|
+ final protected static String USAGE_ARGS =
|
|
|
+ "-readProbability <read probability>\n" +
|
|
|
+ "-writeProbability <write probability>\n" +
|
|
|
+ "-root <root>\n" +
|
|
|
+ "-maxDelayBetweenOps <maxDelayBetweenOpsInMillis>\n" +
|
|
|
+ "-numOfThreads <numOfThreads>\n" +
|
|
|
+ "-elapsedTime <elapsedTimeInSecs>\n" +
|
|
|
+ "-startTime <startTimeInMillis>\n" +
|
|
|
+ "-scriptFile <filename>\n" +
|
|
|
+ "-flagFile <filename>";
|
|
|
+ final private static String USAGE = USAGE_CMD + USAGE_ARGS;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
private final byte[] WRITE_CONTENTS = new byte[4096];
|
|
|
|
|
|
private static final int ERR_TEST_FAILED = 2;
|
|
@@ -151,15 +178,21 @@ public class LoadGenerator extends Configured implements Tool {
|
|
|
hostname = addr.getHostName();
|
|
|
Arrays.fill(WRITE_CONTENTS, (byte) 'a');
|
|
|
}
|
|
|
+
|
|
|
+ public LoadGenerator(Configuration conf) throws IOException, UnknownHostException {
|
|
|
+ this();
|
|
|
+ setConf(conf);
|
|
|
+ }
|
|
|
|
|
|
- private final static int OPEN = 0;
|
|
|
- private final static int LIST = 1;
|
|
|
- private final static int CREATE = 2;
|
|
|
- private final static int WRITE_CLOSE = 3;
|
|
|
- private final static int DELETE = 4;
|
|
|
- private final static int TOTAL_OP_TYPES =5;
|
|
|
- private long [] executionTime = new long[TOTAL_OP_TYPES];
|
|
|
- private long [] totalNumOfOps = new long[TOTAL_OP_TYPES];
|
|
|
+ protected final static int OPEN = 0;
|
|
|
+ protected final static int LIST = 1;
|
|
|
+ protected final static int CREATE = 2;
|
|
|
+ protected final static int WRITE_CLOSE = 3;
|
|
|
+ protected final static int DELETE = 4;
|
|
|
+ protected final static int TOTAL_OP_TYPES =5;
|
|
|
+ protected static long [] executionTime = new long[TOTAL_OP_TYPES];
|
|
|
+ protected static long [] numOfOps = new long[TOTAL_OP_TYPES];
|
|
|
+ protected static long totalOps = 0; // across all of types
|
|
|
|
|
|
/** A thread sends a stream of requests to the NameNode.
|
|
|
* At each iteration, it first decides if it is going to read a file,
|
|
@@ -192,7 +225,7 @@ public class LoadGenerator extends Configured implements Tool {
|
|
|
this.id = id;
|
|
|
}
|
|
|
|
|
|
- /** Main loop
|
|
|
+ /** Main loop for each thread
|
|
|
* Each iteration decides what's the next operation and then pauses.
|
|
|
*/
|
|
|
@Override
|
|
@@ -295,7 +328,7 @@ public class LoadGenerator extends Configured implements Tool {
|
|
|
CreateOpts.createParent(), CreateOpts.bufferSize(4096),
|
|
|
CreateOpts.repFac((short) 3));
|
|
|
executionTime[CREATE] += (Time.now() - startTime);
|
|
|
- totalNumOfOps[CREATE]++;
|
|
|
+ numOfOps[CREATE]++;
|
|
|
|
|
|
long i = fileSize;
|
|
|
while (i > 0) {
|
|
@@ -306,28 +339,67 @@ public class LoadGenerator extends Configured implements Tool {
|
|
|
|
|
|
startTime = Time.now();
|
|
|
executionTime[WRITE_CLOSE] += (Time.now() - startTime);
|
|
|
- totalNumOfOps[WRITE_CLOSE]++;
|
|
|
+ numOfOps[WRITE_CLOSE]++;
|
|
|
} finally {
|
|
|
IOUtils.cleanup(LOG, out);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /** Main function:
|
|
|
+ /** Main function called by tool runner.
|
|
|
* It first initializes data by parsing the command line arguments.
|
|
|
- * It then starts the number of DFSClient threads as specified by
|
|
|
- * the user.
|
|
|
- * It stops all the threads when the specified elapsed time is passed.
|
|
|
- * Before exiting, it prints the average execution for
|
|
|
- * each operation and operation throughput.
|
|
|
+ * It then calls the loadGenerator
|
|
|
*/
|
|
|
@Override
|
|
|
public int run(String[] args) throws Exception {
|
|
|
- int exitCode = init(args);
|
|
|
+ int exitCode = parseArgs(false, args);
|
|
|
if (exitCode != 0) {
|
|
|
return exitCode;
|
|
|
}
|
|
|
+ System.out.println("Running LoadGenerator against fileSystem: " +
|
|
|
+ FileContext.getFileContext().getDefaultFileSystem().getUri());
|
|
|
+ exitCode = generateLoadOnNN();
|
|
|
+ printResults(System.out);
|
|
|
+ return exitCode;
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean stopFileCreated() {
|
|
|
+ try {
|
|
|
+ fc.getFileStatus(flagFile);
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
+ return false;
|
|
|
+ } catch (IOException e) {
|
|
|
+ LOG.error("Got error when checking if file exists:" + flagFile, e);
|
|
|
+ }
|
|
|
+ LOG.info("Flag file was created. Stopping the test.");
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * This is the main function - run threads to generate load on NN
|
|
|
+ * It starts the number of DFSClient threads as specified by
|
|
|
+ * the user.
|
|
|
+ * It stops all the threads when the specified elapsed time is passed.
|
|
|
+ */
|
|
|
+ protected int generateLoadOnNN() throws InterruptedException {
|
|
|
+ int hostHashCode = hostname.hashCode();
|
|
|
+ if (seed == 0) {
|
|
|
+ r = new Random(System.currentTimeMillis()+hostHashCode);
|
|
|
+ } else {
|
|
|
+ r = new Random(seed+hostHashCode);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ fc = FileContext.getFileContext(getConf());
|
|
|
+ } catch (IOException ioe) {
|
|
|
+ System.err.println("Can not initialize the file system: " +
|
|
|
+ ioe.getLocalizedMessage());
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
|
|
|
+ int status = initFileDirTables();
|
|
|
+ if (status != 0) {
|
|
|
+ return status;
|
|
|
+ }
|
|
|
barrier();
|
|
|
|
|
|
DFSClientThread[] threads = new DFSClientThread[numOfThreads];
|
|
@@ -337,91 +409,99 @@ public class LoadGenerator extends Configured implements Tool {
|
|
|
}
|
|
|
|
|
|
if (durations[0] > 0) {
|
|
|
- while(shouldRun) {
|
|
|
- Thread.sleep(durations[currentIndex] * 1000);
|
|
|
- totalTime += durations[currentIndex];
|
|
|
-
|
|
|
- // Are we on the final line of the script?
|
|
|
- if( (currentIndex + 1) == durations.length) {
|
|
|
- shouldRun = false;
|
|
|
- } else {
|
|
|
- if(LOG.isDebugEnabled()) {
|
|
|
- LOG.debug("Moving to index " + currentIndex + ": r = "
|
|
|
- + readProbs[currentIndex] + ", w = " + writeProbs
|
|
|
- + " for duration " + durations[currentIndex]);
|
|
|
+ if (durations.length == 1) {// There is a fixed run time
|
|
|
+ while (shouldRun) {
|
|
|
+ Thread.sleep(2000);
|
|
|
+ totalTime += 2;
|
|
|
+ if (totalTime >= durations[0] || stopFileCreated()) {
|
|
|
+ shouldRun = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // script run
|
|
|
+
|
|
|
+ while (shouldRun) {
|
|
|
+ Thread.sleep(durations[currentIndex] * 1000);
|
|
|
+ totalTime += durations[currentIndex];
|
|
|
+ // Are we on the final line of the script?
|
|
|
+ if ((currentIndex + 1) == durations.length || stopFileCreated()) {
|
|
|
+ shouldRun = false;
|
|
|
+ } else {
|
|
|
+ if (LOG.isDebugEnabled()) {
|
|
|
+ LOG.debug("Moving to index " + currentIndex + ": r = "
|
|
|
+ + readProbs[currentIndex] + ", w = " + writeProbs
|
|
|
+ + " for duration " + durations[currentIndex]);
|
|
|
+ }
|
|
|
+ currentIndex++;
|
|
|
}
|
|
|
- currentIndex++;
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
if(LOG.isDebugEnabled()) {
|
|
|
LOG.debug("Done with testing. Waiting for threads to finish.");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
boolean failed = false;
|
|
|
for (DFSClientThread thread : threads) {
|
|
|
thread.join();
|
|
|
for (int i=0; i<TOTAL_OP_TYPES; i++) {
|
|
|
executionTime[i] += thread.executionTime[i];
|
|
|
- totalNumOfOps[i] += thread.totalNumOfOps[i];
|
|
|
+ numOfOps[i] += thread.totalNumOfOps[i];
|
|
|
}
|
|
|
failed = failed || thread.failed;
|
|
|
}
|
|
|
-
|
|
|
+ int exitCode = 0;
|
|
|
if (failed) {
|
|
|
exitCode = -ERR_TEST_FAILED;
|
|
|
}
|
|
|
|
|
|
- long totalOps = 0;
|
|
|
+ totalOps = 0;
|
|
|
for (int i=0; i<TOTAL_OP_TYPES; i++) {
|
|
|
- totalOps += totalNumOfOps[i];
|
|
|
+ totalOps += numOfOps[i];
|
|
|
}
|
|
|
-
|
|
|
- if (totalNumOfOps[OPEN] != 0) {
|
|
|
- System.out.println("Average open execution time: " +
|
|
|
- (double)executionTime[OPEN]/totalNumOfOps[OPEN] + "ms");
|
|
|
- }
|
|
|
- if (totalNumOfOps[LIST] != 0) {
|
|
|
- System.out.println("Average list execution time: " +
|
|
|
- (double)executionTime[LIST]/totalNumOfOps[LIST] + "ms");
|
|
|
- }
|
|
|
- if (totalNumOfOps[DELETE] != 0) {
|
|
|
- System.out.println("Average deletion execution time: " +
|
|
|
- (double)executionTime[DELETE]/totalNumOfOps[DELETE] + "ms");
|
|
|
- System.out.println("Average create execution time: " +
|
|
|
- (double)executionTime[CREATE]/totalNumOfOps[CREATE] + "ms");
|
|
|
- System.out.println("Average write_close execution time: " +
|
|
|
- (double)executionTime[WRITE_CLOSE]/totalNumOfOps[WRITE_CLOSE] + "ms");
|
|
|
- }
|
|
|
- if (durations[0] != 0) {
|
|
|
- System.out.println("Average operations per second: " +
|
|
|
+ return exitCode;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected static void printResults(PrintStream out) throws UnsupportedFileSystemException {
|
|
|
+ out.println("Result of running LoadGenerator against fileSystem: " +
|
|
|
+ FileContext.getFileContext().getDefaultFileSystem().getUri());
|
|
|
+ if (numOfOps[OPEN] != 0) {
|
|
|
+ out.println("Average open execution time: " +
|
|
|
+ (double)executionTime[OPEN]/numOfOps[OPEN] + "ms");
|
|
|
+ }
|
|
|
+ if (numOfOps[LIST] != 0) {
|
|
|
+ out.println("Average list execution time: " +
|
|
|
+ (double)executionTime[LIST]/numOfOps[LIST] + "ms");
|
|
|
+ }
|
|
|
+ if (numOfOps[DELETE] != 0) {
|
|
|
+ out.println("Average deletion execution time: " +
|
|
|
+ (double)executionTime[DELETE]/numOfOps[DELETE] + "ms");
|
|
|
+ out.println("Average create execution time: " +
|
|
|
+ (double)executionTime[CREATE]/numOfOps[CREATE] + "ms");
|
|
|
+ out.println("Average write_close execution time: " +
|
|
|
+ (double)executionTime[WRITE_CLOSE]/numOfOps[WRITE_CLOSE] + "ms");
|
|
|
+ }
|
|
|
+ if (totalTime != 0) {
|
|
|
+ out.println("Average operations per second: " +
|
|
|
(double)totalOps/totalTime +"ops/s");
|
|
|
}
|
|
|
- System.out.println();
|
|
|
- return exitCode;
|
|
|
+ out.println();
|
|
|
}
|
|
|
+
|
|
|
|
|
|
/** Parse the command line arguments and initialize the data */
|
|
|
- private int init(String[] args) throws IOException {
|
|
|
- try {
|
|
|
- fc = FileContext.getFileContext(getConf());
|
|
|
- } catch (IOException ioe) {
|
|
|
- System.err.println("Can not initialize the file system: " +
|
|
|
- ioe.getLocalizedMessage());
|
|
|
- return -1;
|
|
|
- }
|
|
|
- int hostHashCode = hostname.hashCode();
|
|
|
- boolean scriptSpecified = false;
|
|
|
-
|
|
|
- try {
|
|
|
+ protected int parseArgs(boolean runAsMapReduce, String[] args) throws IOException {
|
|
|
+ try {
|
|
|
for (int i = 0; i < args.length; i++) { // parse command line
|
|
|
if (args[i].equals("-scriptFile")) {
|
|
|
- if(loadScriptFile(args[++i]) == -1)
|
|
|
+ scriptFile = args[++i];
|
|
|
+ if (durations[0] > 0) {
|
|
|
+ System.err.println("Can't specify elapsedTime and use script.");
|
|
|
return -1;
|
|
|
- scriptSpecified = true;
|
|
|
+ }
|
|
|
} else if (args[i].equals("-readProbability")) {
|
|
|
- if(scriptSpecified) {
|
|
|
+ if (scriptFile != null) {
|
|
|
System.err.println("Can't specify probabilities and use script.");
|
|
|
return -1;
|
|
|
}
|
|
@@ -432,7 +512,7 @@ public class LoadGenerator extends Configured implements Tool {
|
|
|
return -1;
|
|
|
}
|
|
|
} else if (args[i].equals("-writeProbability")) {
|
|
|
- if(scriptSpecified) {
|
|
|
+ if (scriptFile != null) {
|
|
|
System.err.println("Can't specify probabilities and use script.");
|
|
|
return -1;
|
|
|
}
|
|
@@ -456,14 +536,18 @@ public class LoadGenerator extends Configured implements Tool {
|
|
|
} else if (args[i].equals("-startTime")) {
|
|
|
startTime = Long.parseLong(args[++i]);
|
|
|
} else if (args[i].equals("-elapsedTime")) {
|
|
|
- if(scriptSpecified) {
|
|
|
+ if (scriptFile != null) {
|
|
|
System.err.println("Can't specify elapsedTime and use script.");
|
|
|
return -1;
|
|
|
}
|
|
|
durations[0] = Long.parseLong(args[++i]);
|
|
|
} else if (args[i].equals("-seed")) {
|
|
|
- r = new Random(Long.parseLong(args[++i])+hostHashCode);
|
|
|
- } else {
|
|
|
+ seed = Long.parseLong(args[++i]);
|
|
|
+ r = new Random(seed);
|
|
|
+ } else if (args[i].equals("-flagFile")) {
|
|
|
+ LOG.info("got flagFile:" + flagFile);
|
|
|
+ flagFile = new Path(args[++i]);
|
|
|
+ }else {
|
|
|
System.err.println(USAGE);
|
|
|
ToolRunner.printGenericCommandUsage(System.err);
|
|
|
return -1;
|
|
@@ -475,6 +559,12 @@ public class LoadGenerator extends Configured implements Tool {
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
+ // Load Script File if not MR; for MR scriptFile is loaded by Mapper
|
|
|
+ if (!runAsMapReduce && scriptFile != null) {
|
|
|
+ if(loadScriptFile(scriptFile, true) == -1)
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
for(int i = 0; i < readProbs.length; i++) {
|
|
|
if (readProbs[i] + writeProbs[i] <0 || readProbs[i]+ writeProbs[i] > 1) {
|
|
|
System.err.println(
|
|
@@ -483,12 +573,7 @@ public class LoadGenerator extends Configured implements Tool {
|
|
|
return -1;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- if (r==null) {
|
|
|
- r = new Random(Time.now()+hostHashCode);
|
|
|
- }
|
|
|
-
|
|
|
- return initFileDirTables();
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
private static void parseScriptLine(String line, ArrayList<Long> duration,
|
|
@@ -527,9 +612,25 @@ public class LoadGenerator extends Configured implements Tool {
|
|
|
* @return 0 if successful, -1 if not
|
|
|
* @throws IOException if errors with file IO
|
|
|
*/
|
|
|
- private int loadScriptFile(String filename) throws IOException {
|
|
|
- FileReader fr = new FileReader(new File(filename));
|
|
|
- BufferedReader br = new BufferedReader(fr);
|
|
|
+ protected static int loadScriptFile(String filename, boolean readLocally) throws IOException {
|
|
|
+
|
|
|
+ FileContext fc;
|
|
|
+ if (readLocally) { // read locally - program is run without MR
|
|
|
+ fc = FileContext.getLocalFSFileContext();
|
|
|
+ } else {
|
|
|
+ fc = FileContext.getFileContext(); // use default file system
|
|
|
+ }
|
|
|
+ DataInputStream in = null;
|
|
|
+ try {
|
|
|
+ in = fc.open(new Path(filename));
|
|
|
+ } catch (IOException e) {
|
|
|
+ System.err.println("Unable to open scriptFile: " + filename);
|
|
|
+
|
|
|
+ System.exit(-1);
|
|
|
+ }
|
|
|
+ InputStreamReader inr = new InputStreamReader(in);
|
|
|
+
|
|
|
+ BufferedReader br = new BufferedReader(inr);
|
|
|
ArrayList<Long> duration = new ArrayList<Long>();
|
|
|
ArrayList<Double> readProb = new ArrayList<Double>();
|
|
|
ArrayList<Double> writeProb = new ArrayList<Double>();
|
|
@@ -619,7 +720,7 @@ public class LoadGenerator extends Configured implements Tool {
|
|
|
* This allows multiple instances of this program, running on clock
|
|
|
* synchronized nodes, to start at roughly the same time.
|
|
|
*/
|
|
|
- private void barrier() {
|
|
|
+ private static void barrier() {
|
|
|
long sleepTime;
|
|
|
while ((sleepTime = startTime - Time.now()) > 0) {
|
|
|
try {
|
|
@@ -635,9 +736,7 @@ public class LoadGenerator extends Configured implements Tool {
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
- int res = ToolRunner.run(new Configuration(),
|
|
|
- new LoadGenerator(), args);
|
|
|
+ int res = ToolRunner.run(new Configuration(), new LoadGenerator(), args);
|
|
|
System.exit(res);
|
|
|
}
|
|
|
-
|
|
|
}
|