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.giraph.combiner.FloatSumMessageCombiner; |
23 | |
import org.apache.giraph.conf.GiraphConfiguration; |
24 | |
import org.apache.giraph.conf.GiraphTypes; |
25 | |
import org.apache.giraph.edge.IntNullArrayEdges; |
26 | |
import org.apache.giraph.graph.Language; |
27 | |
import org.apache.giraph.io.formats.PseudoRandomInputFormatConstants; |
28 | |
import org.apache.giraph.io.formats.PseudoRandomIntNullVertexInputFormat; |
29 | |
import org.apache.giraph.scripting.DeployType; |
30 | |
import org.apache.giraph.scripting.ScriptLoader; |
31 | |
import org.apache.giraph.jython.JythonUtils; |
32 | |
import org.apache.giraph.utils.DistributedCacheUtils; |
33 | |
import org.apache.giraph.utils.ReflectionUtils; |
34 | |
import org.apache.hadoop.fs.Path; |
35 | |
import org.apache.hadoop.util.ToolRunner; |
36 | |
|
37 | |
import com.google.common.collect.Sets; |
38 | |
|
39 | |
import java.util.Set; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | 0 | public class PageRankBenchmark extends GiraphBenchmark { |
45 | |
@Override |
46 | |
public Set<BenchmarkOption> getBenchmarkOptions() { |
47 | 0 | return Sets.newHashSet(BenchmarkOption.VERTICES, |
48 | |
BenchmarkOption.EDGES_PER_VERTEX, BenchmarkOption.SUPERSTEPS, |
49 | |
BenchmarkOption.LOCAL_EDGES_MIN_RATIO, BenchmarkOption.JYTHON, |
50 | |
BenchmarkOption.SCRIPT_PATH); |
51 | |
} |
52 | |
|
53 | |
@Override |
54 | |
protected void prepareConfiguration(GiraphConfiguration conf, |
55 | |
CommandLine cmd) { |
56 | 0 | if (BenchmarkOption.JYTHON.optionTurnedOn(cmd)) { |
57 | 0 | GiraphTypes types = new GiraphTypes(); |
58 | 0 | types.inferFrom(PageRankComputation.class); |
59 | |
|
60 | |
String script; |
61 | |
DeployType deployType; |
62 | 0 | if (BenchmarkOption.SCRIPT_PATH.optionTurnedOn(cmd)) { |
63 | 0 | deployType = DeployType.DISTRIBUTED_CACHE; |
64 | 0 | String path = BenchmarkOption.SCRIPT_PATH.getOptionValue(cmd); |
65 | 0 | Path hadoopPath = new Path(path); |
66 | 0 | Path remotePath = DistributedCacheUtils.copyAndAdd(hadoopPath, conf); |
67 | 0 | script = remotePath.toString(); |
68 | 0 | } else { |
69 | 0 | deployType = DeployType.RESOURCE; |
70 | 0 | script = ReflectionUtils.getPackagePath(this) + "/page-rank.py"; |
71 | |
} |
72 | 0 | ScriptLoader.setScriptsToLoad(conf, script, deployType, Language.JYTHON); |
73 | 0 | types.writeIfUnset(conf); |
74 | 0 | JythonUtils.init(conf, "PageRank"); |
75 | 0 | } else { |
76 | 0 | conf.setComputationClass(PageRankComputation.class); |
77 | |
} |
78 | 0 | conf.setOutEdgesClass(IntNullArrayEdges.class); |
79 | 0 | conf.setMessageCombinerClass(FloatSumMessageCombiner.class); |
80 | 0 | conf.setVertexInputFormatClass( |
81 | |
PseudoRandomIntNullVertexInputFormat.class); |
82 | |
|
83 | 0 | conf.setInt(PseudoRandomInputFormatConstants.AGGREGATE_VERTICES, |
84 | 0 | BenchmarkOption.VERTICES.getOptionIntValue(cmd)); |
85 | 0 | conf.setInt(PseudoRandomInputFormatConstants.EDGES_PER_VERTEX, |
86 | 0 | BenchmarkOption.EDGES_PER_VERTEX.getOptionIntValue(cmd)); |
87 | 0 | conf.setInt(PageRankComputation.SUPERSTEP_COUNT, |
88 | 0 | BenchmarkOption.SUPERSTEPS.getOptionIntValue(cmd)); |
89 | 0 | conf.setFloat(PseudoRandomInputFormatConstants.LOCAL_EDGES_MIN_RATIO, |
90 | 0 | BenchmarkOption.LOCAL_EDGES_MIN_RATIO.getOptionFloatValue(cmd, |
91 | |
PseudoRandomInputFormatConstants.LOCAL_EDGES_MIN_RATIO_DEFAULT)); |
92 | 0 | } |
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
public static void main(final String[] args) throws Exception { |
101 | 0 | System.exit(ToolRunner.run(new PageRankBenchmark(), args)); |
102 | 0 | } |
103 | |
} |