1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.giraph.benchmark; |
20 | |
|
21 | |
import org.apache.commons.cli.CommandLine; |
22 | |
import org.apache.commons.cli.CommandLineParser; |
23 | |
import org.apache.commons.cli.HelpFormatter; |
24 | |
import org.apache.commons.cli.Options; |
25 | |
import org.apache.commons.cli.PosixParser; |
26 | |
import org.apache.giraph.conf.GiraphConfiguration; |
27 | |
import org.apache.giraph.job.GiraphJob; |
28 | |
import org.apache.giraph.utils.LogVersions; |
29 | |
import org.apache.hadoop.conf.Configuration; |
30 | |
import org.apache.hadoop.util.Tool; |
31 | |
import org.apache.log4j.Logger; |
32 | |
|
33 | |
import java.util.Set; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | 0 | public abstract class GiraphBenchmark implements Tool { |
39 | |
|
40 | 0 | private static final Logger LOG = Logger.getLogger(GiraphBenchmark.class); |
41 | |
|
42 | |
private Configuration conf; |
43 | |
|
44 | |
@Override |
45 | |
public void setConf(Configuration conf) { |
46 | 0 | this.conf = conf; |
47 | 0 | } |
48 | |
|
49 | |
@Override |
50 | |
public Configuration getConf() { |
51 | 0 | return conf; |
52 | |
} |
53 | |
|
54 | |
@Override |
55 | |
public int run(String[] args) throws Exception { |
56 | 0 | Set<BenchmarkOption> giraphOptions = getBenchmarkOptions(); |
57 | 0 | giraphOptions.add(BenchmarkOption.HELP); |
58 | 0 | giraphOptions.add(BenchmarkOption.VERBOSE); |
59 | 0 | giraphOptions.add(BenchmarkOption.WORKERS); |
60 | 0 | Options options = new Options(); |
61 | 0 | for (BenchmarkOption giraphOption : giraphOptions) { |
62 | 0 | giraphOption.addToOptions(options); |
63 | 0 | } |
64 | |
|
65 | 0 | HelpFormatter formatter = new HelpFormatter(); |
66 | 0 | if (args.length == 0) { |
67 | 0 | formatter.printHelp(getClass().getName(), options, true); |
68 | 0 | return 0; |
69 | |
} |
70 | 0 | CommandLineParser parser = new PosixParser(); |
71 | 0 | CommandLine cmd = parser.parse(options, args); |
72 | 0 | for (BenchmarkOption giraphOption : giraphOptions) { |
73 | 0 | if (!giraphOption.checkOption(cmd, LOG)) { |
74 | 0 | return -1; |
75 | |
} |
76 | 0 | } |
77 | 0 | if (BenchmarkOption.HELP.optionTurnedOn(cmd)) { |
78 | 0 | formatter.printHelp(getClass().getName(), options, true); |
79 | 0 | return 0; |
80 | |
} |
81 | |
|
82 | 0 | GiraphJob job = new GiraphJob(getConf(), getClass().getName()); |
83 | 0 | int workers = Integer.parseInt(BenchmarkOption.WORKERS.getOptionValue(cmd)); |
84 | |
|
85 | 0 | GiraphConfiguration giraphConf = job.getConfiguration(); |
86 | 0 | giraphConf.addWorkerObserverClass(LogVersions.class); |
87 | 0 | giraphConf.addMasterObserverClass(LogVersions.class); |
88 | |
|
89 | 0 | giraphConf.setWorkerConfiguration(workers, workers, 100.0f); |
90 | 0 | prepareConfiguration(giraphConf, cmd); |
91 | |
|
92 | 0 | boolean isVerbose = false; |
93 | 0 | if (BenchmarkOption.VERBOSE.optionTurnedOn(cmd)) { |
94 | 0 | isVerbose = true; |
95 | |
} |
96 | 0 | if (job.run(isVerbose)) { |
97 | 0 | return 0; |
98 | |
} else { |
99 | 0 | return -1; |
100 | |
} |
101 | |
} |
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
public abstract Set<BenchmarkOption> getBenchmarkOptions(); |
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
protected abstract void prepareConfiguration(GiraphConfiguration conf, |
122 | |
CommandLine cmd); |
123 | |
} |