Coverage Report - org.apache.giraph.benchmark.PageRankBenchmark
 
Classes in this File Line Coverage Branch Coverage Complexity
PageRankBenchmark
12%
7/57
0%
0/22
4.6
 
 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.commons.cli.CommandLineParser;
 23  
 import org.apache.commons.cli.HelpFormatter;
 24  
 import org.apache.commons.cli.Options;
 25  
 import org.apache.commons.cli.PosixParser;
 26  
 import org.apache.giraph.graph.BspUtils;
 27  
 import org.apache.giraph.graph.EdgeListVertex;
 28  
 import org.apache.giraph.graph.GiraphJob;
 29  
 import org.apache.giraph.io.PseudoRandomVertexInputFormat;
 30  
 import org.apache.hadoop.conf.Configuration;
 31  
 import org.apache.hadoop.io.DoubleWritable;
 32  
 import org.apache.hadoop.io.LongWritable;
 33  
 import org.apache.hadoop.util.Tool;
 34  
 import org.apache.hadoop.util.ToolRunner;
 35  
 import org.apache.log4j.Logger;
 36  
 
 37  
 import java.io.IOException;
 38  
 
 39  
 /**
 40  
  * Default Pregel-style PageRank computation using a {@link EdgeListVertex}.
 41  
  */
 42  303
 public class PageRankBenchmark extends EdgeListVertex<
 43  
     LongWritable, DoubleWritable, DoubleWritable, DoubleWritable>
 44  
     implements Tool {
 45  
   /** Class logger */
 46  1
   private static final Logger LOG = Logger.getLogger(PageRankBenchmark.class);
 47  
   /** Configuration from Configurable */
 48  
   private Configuration conf;
 49  
 
 50  
   @Override
 51  
   public void compute(Iterable<DoubleWritable> messages) throws IOException {
 52  1313
     PageRankComputation.computePageRank(this, messages);
 53  1313
   }
 54  
 
 55  
   @Override
 56  
   public Configuration getConf() {
 57  1313
     return conf;
 58  
   }
 59  
 
 60  
   @Override
 61  
   public void setConf(Configuration conf) {
 62  303
     this.conf = conf;
 63  303
   }
 64  
 
 65  
   @Override
 66  
   public final int run(final String[] args) throws Exception {
 67  0
     Options options = new Options();
 68  0
     options.addOption("h", "help", false, "Help");
 69  0
     options.addOption("v", "verbose", false, "Verbose");
 70  0
     options.addOption("w",
 71  
         "workers",
 72  
         true,
 73  
         "Number of workers");
 74  0
     options.addOption("s",
 75  
         "supersteps",
 76  
         true,
 77  
         "Supersteps to execute before finishing");
 78  0
     options.addOption("V",
 79  
         "aggregateVertices",
 80  
         true,
 81  
         "Aggregate vertices");
 82  0
     options.addOption("e",
 83  
         "edgesPerVertex",
 84  
         true,
 85  
         "Edges per vertex");
 86  0
     options.addOption("c",
 87  
         "vertexClass",
 88  
         true,
 89  
         "Vertex class (0 for HashMapVertex, 1 for EdgeListVertex)");
 90  0
     HelpFormatter formatter = new HelpFormatter();
 91  0
     if (args.length == 0) {
 92  0
       formatter.printHelp(getClass().getName(), options, true);
 93  0
       return 0;
 94  
     }
 95  0
     CommandLineParser parser = new PosixParser();
 96  0
     CommandLine cmd = parser.parse(options, args);
 97  0
     if (cmd.hasOption('h')) {
 98  0
       formatter.printHelp(getClass().getName(), options, true);
 99  0
       return 0;
 100  
     }
 101  0
     if (!cmd.hasOption('w')) {
 102  0
       LOG.info("Need to choose the number of workers (-w)");
 103  0
       return -1;
 104  
     }
 105  0
     if (!cmd.hasOption('s')) {
 106  0
       LOG.info("Need to set the number of supersteps (-s)");
 107  0
       return -1;
 108  
     }
 109  0
     if (!cmd.hasOption('V')) {
 110  0
       LOG.info("Need to set the aggregate vertices (-V)");
 111  0
       return -1;
 112  
     }
 113  0
     if (!cmd.hasOption('e')) {
 114  0
       LOG.info("Need to set the number of edges " +
 115  
           "per vertex (-e)");
 116  0
       return -1;
 117  
     }
 118  
 
 119  0
     int workers = Integer.parseInt(cmd.getOptionValue('w'));
 120  0
     GiraphJob job = new GiraphJob(getConf(), getClass().getName());
 121  0
     if (!cmd.hasOption('c') ||
 122  
         (Integer.parseInt(cmd.getOptionValue('c')) == 1)) {
 123  0
       job.setVertexClass(PageRankBenchmark.class);
 124  
     } else {
 125  0
       job.setVertexClass(HashMapVertexPageRankBenchmark.class);
 126  
     }
 127  0
     LOG.info("Using class " +
 128  
         BspUtils.getVertexClass(job.getConfiguration()).getName());
 129  0
     job.setVertexInputFormatClass(PseudoRandomVertexInputFormat.class);
 130  0
     job.setWorkerConfiguration(workers, workers, 100.0f);
 131  0
     job.getConfiguration().setLong(
 132  
         PseudoRandomVertexInputFormat.AGGREGATE_VERTICES,
 133  
         Long.parseLong(cmd.getOptionValue('V')));
 134  0
     job.getConfiguration().setLong(
 135  
         PseudoRandomVertexInputFormat.EDGES_PER_VERTEX,
 136  
         Long.parseLong(cmd.getOptionValue('e')));
 137  0
     job.getConfiguration().setInt(
 138  
         PageRankComputation.SUPERSTEP_COUNT,
 139  
         Integer.parseInt(cmd.getOptionValue('s')));
 140  
 
 141  0
     boolean isVerbose = false;
 142  0
     if (cmd.hasOption('v')) {
 143  0
       isVerbose = true;
 144  
     }
 145  0
     if (cmd.hasOption('s')) {
 146  0
       job.getConfiguration().setInt(
 147  
           PageRankComputation.SUPERSTEP_COUNT,
 148  
           Integer.parseInt(cmd.getOptionValue('s')));
 149  
     }
 150  0
     if (job.run(isVerbose)) {
 151  0
       return 0;
 152  
     } else {
 153  0
       return -1;
 154  
     }
 155  
   }
 156  
 
 157  
   /**
 158  
    * Execute the benchmark.
 159  
    *
 160  
    * @param args Typically the command line arguments.
 161  
    * @throws Exception Any exception from the computation.
 162  
    */
 163  
   public static void main(final String[] args) throws Exception {
 164  0
     System.exit(ToolRunner.run(new PageRankBenchmark(), args));
 165  0
   }
 166  
 }