Uploaded image for project: 'Giraph'
  1. Giraph
  2. GIRAPH-137

De-duplicate pagerank implementation in PageRankBenchmark

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.0.0
    • Component/s: None
    • Labels:

      Description

      Currently in PageRankBenchmark we have the code for pagerank duplicated in each of the implementations of Vertex:

          public static class PageRankHashMapVertex extends HashMapVertex<
                  LongWritable, DoubleWritable, DoubleWritable, DoubleWritable> {
              @Override
              public void compute(Iterator<DoubleWritable> msgIterator) {
                  if (getSuperstep() >= 1) {
                      double sum = 0;
                      while (msgIterator.hasNext()) {
                          sum += msgIterator.next().get();
                      }
                      DoubleWritable vertexValue =
                          new DoubleWritable((0.15f / getNumVertices()) + 0.85f *
                                             sum);
                      setVertexValue(vertexValue);
                  }
      
                  if (getSuperstep() < getConf().getInt(SUPERSTEP_COUNT, -1)) {
                      long edges = getNumOutEdges();
                      sendMsgToAllEdges(
                          new DoubleWritable(getVertexValue().get() / edges));
                  } else {
                      voteToHalt();
                  }
              }
          }
      
          public static class PageRankEdgeListVertex extends EdgeListVertex<
                  LongWritable, DoubleWritable, DoubleWritable, DoubleWritable> {
              @Override
              public void compute(Iterator<DoubleWritable> msgIterator) {
                  if (getSuperstep() >= 1) {
                      double sum = 0;
                      while (msgIterator.hasNext()) {
                          sum += msgIterator.next().get();
                      }
                      DoubleWritable vertexValue =
                          new DoubleWritable((0.15f / getNumVertices()) + 0.85f *
                                             sum);
                      setVertexValue(vertexValue);
                  }
      
                  if (getSuperstep() < getConf().getInt(SUPERSTEP_COUNT, -1)) {
                      long edges = getNumOutEdges();
                      sendMsgToAllEdges(
                              new DoubleWritable(getVertexValue().get() / edges));
                  } else {
                      voteToHalt();
                  }
              }
          }

      This code can be consolidated into private class and the two implementations just extend that.

        Attachments

        1. GIRAPH-137.patch
          4 kB
          Harsh J

          Activity

            People

            • Assignee:
              qwertymaniac Harsh J
              Reporter:
              jghoman Jakob Homan
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: