Coverage Report - org.apache.giraph.benchmark.WeightedPageRankBenchmark
 
Classes in this File Line Coverage Branch Coverage Complexity
WeightedPageRankBenchmark
0%
0/49
0%
0/14
4
 
 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  
 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  
  * Benchmark for {@link WeightedPageRankComputation}
 42  
  */
 43  0
 public class WeightedPageRankBenchmark extends GiraphBenchmark {
 44  
   /** Class logger */
 45  0
   private static final Logger LOG =
 46  0
       Logger.getLogger(WeightedPageRankBenchmark.class);
 47  
 
 48  
   /** Option for OutEdges class */
 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  
   /** Option for using edge input */
 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  
   /** Option for partitioning algorithm */
 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  
   /** Option for type of combiner */
 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  
   /** Option for output format */
 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  
    * Set vertex edges, input format, partitioner classes and related parameters
 86  
    * based on command-line arguments.
 87  
    *
 88  
    * @param cmd           Command line arguments
 89  
    * @param configuration Giraph job configuration
 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  
    * Execute the benchmark.
 160  
    *
 161  
    * @param args Typically the command line arguments.
 162  
    * @throws Exception Any exception from the computation.
 163  
    */
 164  
   public static void main(final String[] args) throws Exception {
 165  0
     System.exit(ToolRunner.run(new WeightedPageRankBenchmark(), args));
 166  0
   }
 167  
 }