1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * distributed under the License is distributed on an "AS IS" BASIS,14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15 * See the License for the specific language governing permissions and16 * limitations under the License.17 */1819package org.apache.giraph.benchmark;
2021import org.apache.commons.cli.CommandLine;
22import org.apache.giraph.combiner.MinimumDoubleMessageCombiner;
23import org.apache.giraph.conf.GiraphConfiguration;
24import org.apache.giraph.conf.GiraphConstants;
25import org.apache.giraph.edge.ArrayListEdges;
26import org.apache.giraph.edge.HashMapEdges;
27import org.apache.giraph.io.formats.PseudoRandomInputFormatConstants;
28import org.apache.giraph.io.formats.PseudoRandomVertexInputFormat;
29import org.apache.hadoop.util.ToolRunner;
30import org.apache.log4j.Logger;
3132import com.google.common.collect.Sets;
3334import java.util.Set;
3536/**37 * Single-source shortest paths benchmark.38 */39publicclassShortestPathsBenchmarkextendsGiraphBenchmark {
40/** Class logger */41privatestaticfinal Logger LOG =
42 Logger.getLogger(ShortestPathsBenchmark.class);
4344/** Option for OutEdges class */45privatestaticfinalBenchmarkOption EDGES_CLASS = newBenchmarkOption(
46"c", "edgesClass", true,
47"Vertex edges class (0 for HashMapEdges, 1 for ArrayListEdges)");
48/** Option for not using combiner */49privatestaticfinalBenchmarkOption NO_COMBINER = newBenchmarkOption(
50"nc", "noCombiner", false, "Don't use a combiner");
5152 @Override
53public Set<BenchmarkOption> getBenchmarkOptions() {
54return Sets.newHashSet(BenchmarkOption.VERTICES,
55 BenchmarkOption.EDGES_PER_VERTEX, EDGES_CLASS, NO_COMBINER);
56 }
5758 @Override
59protectedvoid prepareConfiguration(GiraphConfiguration conf,
60 CommandLine cmd) {
61 conf.setComputationClass(ShortestPathsComputation.class);
62if (EDGES_CLASS.getOptionIntValue(cmd, 1) == 1) {
63 conf.setOutEdgesClass(ArrayListEdges.class);
64 } else {
65 conf.setOutEdgesClass(HashMapEdges.class);
66 }
67 LOG.info("Using class " + GiraphConstants.COMPUTATION_CLASS.get(conf));
68 conf.setVertexInputFormatClass(PseudoRandomVertexInputFormat.class);
69if (!NO_COMBINER.optionTurnedOn(cmd)) {
70 conf.setMessageCombinerClass(MinimumDoubleMessageCombiner.class);
71 }
72 conf.setLong(PseudoRandomInputFormatConstants.AGGREGATE_VERTICES,
73 BenchmarkOption.VERTICES.getOptionLongValue(cmd));
74 conf.setLong(PseudoRandomInputFormatConstants.EDGES_PER_VERTEX,
75 BenchmarkOption.EDGES_PER_VERTEX.getOptionLongValue(cmd));
76 }
7778/**79 * Execute the benchmark.80 *81 * @param args Typically the command line arguments.82 * @throws Exception Any exception from the computation.83 */84publicstaticvoid main(final String[] args) throws Exception {
85 System.exit(ToolRunner.run(newShortestPathsBenchmark(), args));
86 }
87 }