This project has retired. For details please refer to its Attic page.
PageRankBenchmark xref
View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * 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 and
16   * limitations under the License.
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   * Benchmark for {@link PageRankComputation}
43   */
44  public class PageRankBenchmark extends GiraphBenchmark {
45    @Override
46    public Set<BenchmarkOption> getBenchmarkOptions() {
47      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      if (BenchmarkOption.JYTHON.optionTurnedOn(cmd)) {
57        GiraphTypes types = new GiraphTypes();
58        types.inferFrom(PageRankComputation.class);
59  
60        String script;
61        DeployType deployType;
62        if (BenchmarkOption.SCRIPT_PATH.optionTurnedOn(cmd)) {
63          deployType = DeployType.DISTRIBUTED_CACHE;
64          String path = BenchmarkOption.SCRIPT_PATH.getOptionValue(cmd);
65          Path hadoopPath = new Path(path);
66          Path remotePath = DistributedCacheUtils.copyAndAdd(hadoopPath, conf);
67          script = remotePath.toString();
68        } else {
69          deployType = DeployType.RESOURCE;
70          script = ReflectionUtils.getPackagePath(this) + "/page-rank.py";
71        }
72        ScriptLoader.setScriptsToLoad(conf, script, deployType, Language.JYTHON);
73        types.writeIfUnset(conf);
74        JythonUtils.init(conf, "PageRank");
75      } else {
76        conf.setComputationClass(PageRankComputation.class);
77      }
78      conf.setOutEdgesClass(IntNullArrayEdges.class);
79      conf.setMessageCombinerClass(FloatSumMessageCombiner.class);
80      conf.setVertexInputFormatClass(
81          PseudoRandomIntNullVertexInputFormat.class);
82  
83      conf.setInt(PseudoRandomInputFormatConstants.AGGREGATE_VERTICES,
84          BenchmarkOption.VERTICES.getOptionIntValue(cmd));
85      conf.setInt(PseudoRandomInputFormatConstants.EDGES_PER_VERTEX,
86          BenchmarkOption.EDGES_PER_VERTEX.getOptionIntValue(cmd));
87      conf.setInt(PageRankComputation.SUPERSTEP_COUNT,
88          BenchmarkOption.SUPERSTEPS.getOptionIntValue(cmd));
89      conf.setFloat(PseudoRandomInputFormatConstants.LOCAL_EDGES_MIN_RATIO,
90          BenchmarkOption.LOCAL_EDGES_MIN_RATIO.getOptionFloatValue(cmd,
91              PseudoRandomInputFormatConstants.LOCAL_EDGES_MIN_RATIO_DEFAULT));
92    }
93  
94    /**
95     * Execute the benchmark.
96     *
97     * @param args Typically the command line arguments.
98     * @throws Exception Any exception from the computation.
99     */
100   public static void main(final String[] args) throws Exception {
101     System.exit(ToolRunner.run(new PageRankBenchmark(), args));
102   }
103 }