-
Notifications
You must be signed in to change notification settings - Fork 8.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MAPREDUCE-7469. NNBench createControlFiles should use thread pool to improve performance. #6463
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,9 +26,15 @@ | |
import java.io.InputStreamReader; | ||
import java.io.PrintStream; | ||
import java.text.SimpleDateFormat; | ||
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.StringTokenizer; | ||
import java.util.concurrent.Callable; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Future; | ||
|
||
import org.apache.hadoop.HadoopIllegalArgumentException; | ||
import org.apache.hadoop.conf.Configuration; | ||
|
@@ -55,6 +61,7 @@ | |
import org.apache.hadoop.mapred.SequenceFileInputFormat; | ||
import org.apache.hadoop.util.Tool; | ||
import org.apache.hadoop.util.ToolRunner; | ||
import org.apache.hadoop.util.concurrent.HadoopExecutors; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
|
@@ -105,6 +112,8 @@ public class NNBench extends Configured implements Tool { | |
private static final String OP_RENAME = "rename"; | ||
private static final String OP_DELETE = "delete"; | ||
private static final int MAX_OPERATION_EXCEPTIONS = 1000; | ||
private ExecutorService executorService = | ||
HadoopExecutors.newFixedThreadPool(2 * Runtime.getRuntime().availableProcessors()); | ||
|
||
// To display in the format that matches the NN and DN log format | ||
// Example: 2007-10-26 00:01:19,853 | ||
|
@@ -134,27 +143,60 @@ private void cleanupBeforeTestrun() throws IOException { | |
* | ||
* @throws IOException on error | ||
*/ | ||
private void createControlFiles() throws IOException { | ||
private void createControlFiles() throws ExecutionException, InterruptedException { | ||
LOG.info("Creating " + numberOfMaps + " control files"); | ||
|
||
List<Future<Void>> list = new ArrayList<>(); | ||
for (int i = 0; i < numberOfMaps; i++) { | ||
String strFileName = "NNBench_Controlfile_" + i; | ||
Path filePath = new Path(new Path(baseDir, CONTROL_DIR_NAME), | ||
strFileName); | ||
|
||
Future<Void> future = executorService.submit(new CreateControlFile(strFileName, filePath, i)); | ||
list.add(future); | ||
} | ||
|
||
for (int i = 0; i < list.size(); i++) { | ||
try { | ||
list.get(i).get(); | ||
} catch (InterruptedException | ExecutionException e) { | ||
LOG.error("Creating control files Error."); | ||
throw e; | ||
} | ||
} | ||
|
||
executorService.shutdown(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we are shutting down the service, should we spawn executorService in this method only instead of creating at object creation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Thanks. |
||
} | ||
|
||
private class CreateControlFile implements Callable<Void> { | ||
private String strFileName; | ||
private Path filePath; | ||
private int order; | ||
|
||
CreateControlFile(String strFileName, Path filePath, int order) { | ||
this.strFileName = strFileName; | ||
this.filePath = filePath; | ||
this.order = order; | ||
} | ||
|
||
@Override | ||
public Void call() throws Exception { | ||
SequenceFile.Writer writer = null; | ||
try { | ||
writer = SequenceFile.createWriter(getConf(), Writer.file(filePath), | ||
Writer.keyClass(Text.class), Writer.valueClass(LongWritable.class), | ||
Writer.compression(CompressionType.NONE)); | ||
writer.append(new Text(strFileName), new LongWritable(i)); | ||
writer.append(new Text(strFileName), new LongWritable(order)); | ||
} finally { | ||
if (writer != null) { | ||
writer.close(); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Display version | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOG.error("Creating control files Error.", e);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed. Thanks