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.graph.BspUtils; |
27 | |
import org.apache.giraph.graph.EdgeListVertex; |
28 | |
import org.apache.giraph.graph.GiraphJob; |
29 | |
import org.apache.giraph.io.PseudoRandomVertexInputFormat; |
30 | |
import org.apache.hadoop.conf.Configuration; |
31 | |
import org.apache.hadoop.io.DoubleWritable; |
32 | |
import org.apache.hadoop.io.LongWritable; |
33 | |
import org.apache.hadoop.util.Tool; |
34 | |
import org.apache.hadoop.util.ToolRunner; |
35 | |
import org.apache.log4j.Logger; |
36 | |
|
37 | |
import java.io.IOException; |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | 303 | public class PageRankBenchmark extends EdgeListVertex< |
43 | |
LongWritable, DoubleWritable, DoubleWritable, DoubleWritable> |
44 | |
implements Tool { |
45 | |
|
46 | 1 | private static final Logger LOG = Logger.getLogger(PageRankBenchmark.class); |
47 | |
|
48 | |
private Configuration conf; |
49 | |
|
50 | |
@Override |
51 | |
public void compute(Iterable<DoubleWritable> messages) throws IOException { |
52 | 1313 | PageRankComputation.computePageRank(this, messages); |
53 | 1313 | } |
54 | |
|
55 | |
@Override |
56 | |
public Configuration getConf() { |
57 | 1313 | return conf; |
58 | |
} |
59 | |
|
60 | |
@Override |
61 | |
public void setConf(Configuration conf) { |
62 | 303 | this.conf = conf; |
63 | 303 | } |
64 | |
|
65 | |
@Override |
66 | |
public final int run(final String[] args) throws Exception { |
67 | 0 | Options options = new Options(); |
68 | 0 | options.addOption("h", "help", false, "Help"); |
69 | 0 | options.addOption("v", "verbose", false, "Verbose"); |
70 | 0 | options.addOption("w", |
71 | |
"workers", |
72 | |
true, |
73 | |
"Number of workers"); |
74 | 0 | options.addOption("s", |
75 | |
"supersteps", |
76 | |
true, |
77 | |
"Supersteps to execute before finishing"); |
78 | 0 | options.addOption("V", |
79 | |
"aggregateVertices", |
80 | |
true, |
81 | |
"Aggregate vertices"); |
82 | 0 | options.addOption("e", |
83 | |
"edgesPerVertex", |
84 | |
true, |
85 | |
"Edges per vertex"); |
86 | 0 | options.addOption("c", |
87 | |
"vertexClass", |
88 | |
true, |
89 | |
"Vertex class (0 for HashMapVertex, 1 for EdgeListVertex)"); |
90 | 0 | HelpFormatter formatter = new HelpFormatter(); |
91 | 0 | if (args.length == 0) { |
92 | 0 | formatter.printHelp(getClass().getName(), options, true); |
93 | 0 | return 0; |
94 | |
} |
95 | 0 | CommandLineParser parser = new PosixParser(); |
96 | 0 | CommandLine cmd = parser.parse(options, args); |
97 | 0 | if (cmd.hasOption('h')) { |
98 | 0 | formatter.printHelp(getClass().getName(), options, true); |
99 | 0 | return 0; |
100 | |
} |
101 | 0 | if (!cmd.hasOption('w')) { |
102 | 0 | LOG.info("Need to choose the number of workers (-w)"); |
103 | 0 | return -1; |
104 | |
} |
105 | 0 | if (!cmd.hasOption('s')) { |
106 | 0 | LOG.info("Need to set the number of supersteps (-s)"); |
107 | 0 | return -1; |
108 | |
} |
109 | 0 | if (!cmd.hasOption('V')) { |
110 | 0 | LOG.info("Need to set the aggregate vertices (-V)"); |
111 | 0 | return -1; |
112 | |
} |
113 | 0 | if (!cmd.hasOption('e')) { |
114 | 0 | LOG.info("Need to set the number of edges " + |
115 | |
"per vertex (-e)"); |
116 | 0 | return -1; |
117 | |
} |
118 | |
|
119 | 0 | int workers = Integer.parseInt(cmd.getOptionValue('w')); |
120 | 0 | GiraphJob job = new GiraphJob(getConf(), getClass().getName()); |
121 | 0 | if (!cmd.hasOption('c') || |
122 | |
(Integer.parseInt(cmd.getOptionValue('c')) == 1)) { |
123 | 0 | job.setVertexClass(PageRankBenchmark.class); |
124 | |
} else { |
125 | 0 | job.setVertexClass(HashMapVertexPageRankBenchmark.class); |
126 | |
} |
127 | 0 | LOG.info("Using class " + |
128 | |
BspUtils.getVertexClass(job.getConfiguration()).getName()); |
129 | 0 | job.setVertexInputFormatClass(PseudoRandomVertexInputFormat.class); |
130 | 0 | job.setWorkerConfiguration(workers, workers, 100.0f); |
131 | 0 | job.getConfiguration().setLong( |
132 | |
PseudoRandomVertexInputFormat.AGGREGATE_VERTICES, |
133 | |
Long.parseLong(cmd.getOptionValue('V'))); |
134 | 0 | job.getConfiguration().setLong( |
135 | |
PseudoRandomVertexInputFormat.EDGES_PER_VERTEX, |
136 | |
Long.parseLong(cmd.getOptionValue('e'))); |
137 | 0 | job.getConfiguration().setInt( |
138 | |
PageRankComputation.SUPERSTEP_COUNT, |
139 | |
Integer.parseInt(cmd.getOptionValue('s'))); |
140 | |
|
141 | 0 | boolean isVerbose = false; |
142 | 0 | if (cmd.hasOption('v')) { |
143 | 0 | isVerbose = true; |
144 | |
} |
145 | 0 | if (cmd.hasOption('s')) { |
146 | 0 | job.getConfiguration().setInt( |
147 | |
PageRankComputation.SUPERSTEP_COUNT, |
148 | |
Integer.parseInt(cmd.getOptionValue('s'))); |
149 | |
} |
150 | 0 | if (job.run(isVerbose)) { |
151 | 0 | return 0; |
152 | |
} else { |
153 | 0 | return -1; |
154 | |
} |
155 | |
} |
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
public static void main(final String[] args) throws Exception { |
164 | 0 | System.exit(ToolRunner.run(new PageRankBenchmark(), args)); |
165 | 0 | } |
166 | |
} |