다음과 같은 hadoop 프로그램이 있습니다. relavent 코드 스 니펫을 넣습니다. main에서 BiG_DATA를 읽는 인수를 true로 전달합니다. 주된 내용은 "Working on Big data"입니다. 그러나 RowPreMap 클래스에서 map 메소드를 사용할 때 BIG_DATA의 값은 초기화 값인 false입니다. 왜 이런 일이 일어나는지 확신 할 수 없습니다. 내가 놓친 게 있니? 이것은 독립 실행 형 시스템에서이 작업을 실행할 때 작동하지만 hadoop 클러스터에서이 작업을 수행 할 때는 작동하지 않습니다. 작업은 JobControl에 의해 처리됩니다. 쓰레드가있는 것입니까?Hadoop Cluster에서 다른 클래스의 정적 변수 사용
공용 클래스 UVDriver 구성이 도구 {
public static class RowMPreMap extends MapReduceBase implements
Mapper<LongWritable, Text, Text, Text> {
private Text keyText = new Text();
private Text valText = new Text();
public void map(LongWritable key, Text value,
OutputCollector<Text, Text> output, Reporter reporter)
throws IOException {
// Input: (lineNo, lineContent)
// Split each line using seperator based on the dataset.
String line[] = null;
if (Settings.BIG_DATA)
line = value.toString().split("::");
else
line = value.toString().split("\\s");
keyText.set(line[0]);
valText.set(line[1] + "," + line[2]);
// Output: (userid, "movieid,rating")
output.collect(keyText, valText);
}
}
public static class Settings {
public static boolean BIG_DATA = false;
public static int noOfUsers = 0;
public static int noOfMovies = 0;
public static final int noOfCommonFeatures = 10;
public static final int noOfIterationsRequired = 3;
public static final float INITIAL_VALUE = 0.1f;
public static final String NORMALIZE_DATA_PATH_TEMP = "normalize_temp";
public static final String NORMALIZE_DATA_PATH = "normalize";
public static String INPUT_PATH = "input";
public static String OUTPUT_PATH = "output";
public static String TEMP_PATH = "temp";
}
public static class Constants {
public static final int BIG_DATA_USERS = 71567;
public static final int BIG_DATA_MOVIES = 10681;
public static final int SMALL_DATA_USERS = 943;
public static final int SMALL_DATA_MOVIES = 1682;
public static final int M_Matrix = 1;
public static final int U_Matrix = 2;
public static final int V_Matrix = 3;
}
public int run(String[] args) throws Exception {
// 1. Pre-process the data.
// a) Normalize
// 2. Initialize the U, V Matrices
// a) Initialize U Matrix
// b) Initialize V Matrix
// 3. Iterate to update U and V.
// Write Job details for each of the above steps.
Settings.INPUT_PATH = args[0];
Settings.OUTPUT_PATH = args[1];
Settings.TEMP_PATH = args[2];
Settings.BIG_DATA = Boolean.parseBoolean(args[3]);
if (Settings.BIG_DATA) {
System.out.println("Working on BIG DATA.");
Settings.noOfUsers = Constants.BIG_DATA_USERS;
Settings.noOfMovies = Constants.BIG_DATA_MOVIES;
} else {
System.out.println("Working on Small DATA.");
Settings.noOfUsers = Constants.SMALL_DATA_USERS;
Settings.noOfMovies = Constants.SMALL_DATA_MOVIES;
}
// some code here
handleRun(control);
return 0;
}
public static void main(String args[]) throws Exception {
System.out.println("Program started");
if (args.length != 4) {
System.err
.println("Usage: UVDriver <input path> <output path> <fs path>");
System.exit(-1);
}
Configuration configuration = new Configuration();
String[] otherArgs = new GenericOptionsParser(configuration, args)
.getRemainingArgs();
ToolRunner.run(new UVDriver(), otherArgs);
System.out.println("Program complete.");
System.exit(0);
}
}
작업 제어를 구현 확장합니다. 정적 수정의 범위는 JVM (훨씬 적은 네트워크.)
지도 작업은 항상 별도의 JVM에서 실행의 여러 인스턴스에 걸쳐 있지 않기 때문에
public static class JobRunner implements Runnable {
private JobControl control;
public JobRunner(JobControl _control) {
this.control = _control;
}
public void run() {
this.control.run();
}
}
public static void handleRun(JobControl control)
throws InterruptedException {
JobRunner runner = new JobRunner(control);
Thread t = new Thread(runner);
t.start();
int i = 0;
while (!control.allFinished()) {
if (i % 20 == 0) {
System.out
.println(new Date().toString() + ": Still running...");
System.out.println("Running jobs: "
+ control.getRunningJobs().toString());
System.out.println("Waiting jobs: "
+ control.getWaitingJobs().toString());
System.out.println("Successful jobs: "
+ control.getSuccessfulJobs().toString());
}
Thread.sleep(1000);
i++;
}
if (control.getFailedJobs() != null) {
System.out.println("Failed jobs: "
+ control.getFailedJobs().toString());
}
}
Hadoop 분산 모드를 사용할 때 다른 클래스의 정적 변수를 사용하는 것이 좋지 않은 것처럼 보입니다. 그것들에 접근하는 유일한 방법은 설정 객체에 설정하는 것입니다. – TechCrunch
예. JobConf에 변수를 넣고 Mapper에있는'configure'를 오버라이드하여 접근하십시오. http://hadoop.apache.org/docs/r1.1.1/api/org/apache/hadoop/mapred/Mapper.html – Scott
저는 이것을 정확히이 방법으로 사용했으며 지금은 작동합니다. 게시물에서 언급 한 방식이 효과가없는 이유를 이해하려고합니다. – TechCrunch