1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
package org.apache.giraph.benchmark; |
19 | |
|
20 | |
import org.apache.commons.cli.CommandLine; |
21 | |
import org.apache.giraph.combiner.DoubleSumMessageCombiner; |
22 | |
import org.apache.giraph.conf.GiraphConfiguration; |
23 | |
import org.apache.giraph.conf.GiraphConstants; |
24 | |
import org.apache.giraph.edge.ArrayListEdges; |
25 | |
import org.apache.giraph.edge.ByteArrayEdges; |
26 | |
import org.apache.giraph.edge.HashMapEdges; |
27 | |
import org.apache.giraph.edge.LongDoubleArrayEdges; |
28 | |
import org.apache.giraph.io.formats.PseudoRandomInputFormatConstants; |
29 | |
import org.apache.giraph.io.formats.JsonBase64VertexOutputFormat; |
30 | |
import org.apache.giraph.io.formats.PseudoRandomEdgeInputFormat; |
31 | |
import org.apache.giraph.io.formats.PseudoRandomVertexInputFormat; |
32 | |
import org.apache.giraph.partition.SimpleLongRangePartitionerFactory; |
33 | |
import org.apache.hadoop.util.ToolRunner; |
34 | |
import org.apache.log4j.Logger; |
35 | |
|
36 | |
import com.google.common.collect.Sets; |
37 | |
|
38 | |
import java.util.Set; |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | 0 | public class WeightedPageRankBenchmark extends GiraphBenchmark { |
44 | |
|
45 | 0 | private static final Logger LOG = |
46 | 0 | Logger.getLogger(WeightedPageRankBenchmark.class); |
47 | |
|
48 | |
|
49 | 0 | private static final BenchmarkOption EDGES_CLASS = new BenchmarkOption( |
50 | |
"c", "edgesClass", true, |
51 | |
"Vertex edges class (0 for LongDoubleArrayEdges," + |
52 | |
"1 for ByteArrayEdges, " + |
53 | |
"2 for ByteArrayEdges with unsafe serialization, " + |
54 | |
"3 for ArrayListEdges, " + |
55 | |
"4 for HashMapVertex"); |
56 | |
|
57 | 0 | private static final BenchmarkOption EDGE_INPUT = new BenchmarkOption( |
58 | |
"ei", "edgeInput", false, |
59 | |
"Use edge-based input instead of vertex-based input."); |
60 | |
|
61 | 0 | private static final BenchmarkOption PARTITIONER = new BenchmarkOption( |
62 | |
"p", "partitioner", true, |
63 | |
"Partitioning algorithm (0 for hash partitioning (default), " + |
64 | |
"1 for range partitioning)"); |
65 | |
|
66 | 0 | private static final BenchmarkOption MESSAGE_COMBINER_TYPE = |
67 | |
new BenchmarkOption("t", "combinerType", true, |
68 | |
"MessageCombiner type (0 for no combiner," + |
69 | |
" 1 for DoubleSumMessageCombiner (default)"); |
70 | |
|
71 | 0 | private static final BenchmarkOption OUTPUT_FORMAT = new BenchmarkOption( |
72 | |
"o", "vertexOutputFormat", true, |
73 | |
"0 for JsonBase64VertexOutputFormat"); |
74 | |
|
75 | |
@Override |
76 | |
public Set<BenchmarkOption> getBenchmarkOptions() { |
77 | 0 | return Sets.newHashSet( |
78 | |
BenchmarkOption.SUPERSTEPS, BenchmarkOption.VERTICES, |
79 | |
BenchmarkOption.EDGES_PER_VERTEX, BenchmarkOption.LOCAL_EDGES_MIN_RATIO, |
80 | |
EDGES_CLASS, EDGE_INPUT, PARTITIONER, |
81 | |
MESSAGE_COMBINER_TYPE, OUTPUT_FORMAT); |
82 | |
} |
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
protected void prepareConfiguration(GiraphConfiguration configuration, |
92 | |
CommandLine cmd) { |
93 | 0 | configuration.setComputationClass(WeightedPageRankComputation.class); |
94 | 0 | int edgesClassOption = EDGES_CLASS.getOptionIntValue(cmd, 1); |
95 | 0 | switch (edgesClassOption) { |
96 | |
case 0: |
97 | 0 | configuration.setOutEdgesClass(LongDoubleArrayEdges.class); |
98 | 0 | break; |
99 | |
case 1: |
100 | 0 | configuration.setOutEdgesClass(ByteArrayEdges.class); |
101 | 0 | break; |
102 | |
case 2: |
103 | 0 | configuration.setOutEdgesClass(ByteArrayEdges.class); |
104 | 0 | configuration.useUnsafeSerialization(true); |
105 | 0 | break; |
106 | |
case 3: |
107 | 0 | configuration.setOutEdgesClass(ArrayListEdges.class); |
108 | 0 | break; |
109 | |
case 4: |
110 | 0 | configuration.setOutEdgesClass(HashMapEdges.class); |
111 | 0 | break; |
112 | |
default: |
113 | 0 | LOG.info("Unknown OutEdges class, " + |
114 | |
"defaulting to LongDoubleArrayEdges"); |
115 | 0 | configuration.setOutEdgesClass(LongDoubleArrayEdges.class); |
116 | |
} |
117 | |
|
118 | 0 | LOG.info("Using edges class " + |
119 | 0 | GiraphConstants.VERTEX_EDGES_CLASS.get(configuration)); |
120 | 0 | if (MESSAGE_COMBINER_TYPE.getOptionIntValue(cmd, 1) == 1) { |
121 | 0 | configuration.setMessageCombinerClass(DoubleSumMessageCombiner.class); |
122 | |
} |
123 | |
|
124 | 0 | if (EDGE_INPUT.optionTurnedOn(cmd)) { |
125 | 0 | configuration.setEdgeInputFormatClass(PseudoRandomEdgeInputFormat.class); |
126 | |
} else { |
127 | 0 | configuration.setVertexInputFormatClass( |
128 | |
PseudoRandomVertexInputFormat.class); |
129 | |
} |
130 | |
|
131 | 0 | configuration.setLong( |
132 | |
PseudoRandomInputFormatConstants.AGGREGATE_VERTICES, |
133 | 0 | BenchmarkOption.VERTICES.getOptionLongValue(cmd)); |
134 | 0 | configuration.setLong( |
135 | |
PseudoRandomInputFormatConstants.EDGES_PER_VERTEX, |
136 | 0 | BenchmarkOption.EDGES_PER_VERTEX.getOptionLongValue(cmd)); |
137 | 0 | configuration.setFloat( |
138 | |
PseudoRandomInputFormatConstants.LOCAL_EDGES_MIN_RATIO, |
139 | 0 | BenchmarkOption.LOCAL_EDGES_MIN_RATIO.getOptionFloatValue(cmd, |
140 | |
PseudoRandomInputFormatConstants.LOCAL_EDGES_MIN_RATIO_DEFAULT)); |
141 | |
|
142 | 0 | if (OUTPUT_FORMAT.getOptionIntValue(cmd, -1) == 0) { |
143 | 0 | LOG.info("Using vertex output format class " + |
144 | 0 | JsonBase64VertexOutputFormat.class.getName()); |
145 | 0 | configuration.setVertexOutputFormatClass( |
146 | |
JsonBase64VertexOutputFormat.class); |
147 | |
} |
148 | |
|
149 | 0 | if (PARTITIONER.getOptionIntValue(cmd, 0) == 1) { |
150 | 0 | configuration.setGraphPartitionerFactoryClass( |
151 | |
SimpleLongRangePartitionerFactory.class); |
152 | |
} |
153 | |
|
154 | 0 | configuration.setInt(WeightedPageRankComputation.SUPERSTEP_COUNT, |
155 | 0 | BenchmarkOption.SUPERSTEPS.getOptionIntValue(cmd)); |
156 | 0 | } |
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
public static void main(final String[] args) throws Exception { |
165 | 0 | System.exit(ToolRunner.run(new WeightedPageRankBenchmark(), args)); |
166 | 0 | } |
167 | |
} |