Coverage Report - org.apache.giraph.benchmark.PageRankBenchmark
 
Classes in this File Line Coverage Branch Coverage Complexity
PageRankBenchmark
0%
0/33
0%
0/4
1.667
 
 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  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  
    * 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  0
     System.exit(ToolRunner.run(new PageRankBenchmark(), args));
 102  0
   }
 103  
 }