Code Monkey home page Code Monkey logo

spark-pagerank's Introduction

buildstatus

PageRank in Spark

This is an implementation of PageRank in Spark, using Spark's standard RDD API.

Features

  • Fast iterations
  • Parameterised "teleport" probability
  • Weighted edges (out-edge weights must be normalized)
  • Supports "dangling" vertices (no out-edges from a node)
  • Supports arbitrary (e.g. non-uniform) priors (as vertex values)
  • Various stopping criteria:
    • Number of iterations threshold
    • Convergence threshold (requires additional computation after each iteration)
  • Utilities for building, preparing, and validating input graphs (incl. out-edge normalization)

Usage

Include it as a dependency in your sbt project: "com.soundcloud" %% "spark-pagerank" % <version>

As A Library

You can use PageRank in Spark as a library and call it from within your own drivers. You will want to do this when you have some data preparation to do that does not conform with the built-in driver data interfaces.

More examples of usage as a library can be found in the source of the built-in drivers (see below).

As Drivers

We include several built-in drivers that operate on plain-text TSV input of labeled edges as a starting point. You will prepare the graph and run PageRank in the following sequence of drivers. Use --help to see the arguments and usage of each driver.

  1. com.soundcloud.spark.pagerank.GraphBuilderApp: Builds a PageRank graph from (non-normalized) weighted edges in TSV format (source, destination, weight), saving the resulting graph (edges and vertices) in Parquet files in preparation for next steps.
  2. com.soundcloud.spark.pagerank.PageRankApp: Runs PageRank on the graph produced using the functions in PageRankGraph or by using the GraphBuilderApp.
  3. com.soundcloud.spark.pagerank.ConvergenceCheckApp: Compares two PageRank vectors and lets the user determine if there is convergence by outputting the sum of the component-wise difference of the vectors. Note that this is an optional tool that is mostly used for debugging. If the user is concerned with iterating until convergence, the user can specify the convergence threshold at runtime to PageRank.

Performance

We run this library on one of our behavior graphs which consists of approximately 700M vertices and 15B edges. Using the following Spark configuration, and in-memory persistence of edge and vertex RDDs, we obtain iteration times on the order of 3-5 minutes each.

Configuration example:

  • Spark 2.1.1
  • YARN
  • Dynamic allocation: no
  • Number of executors: 256
  • Number of executor cores: 4
  • Executor memory: 28G

Performance Tuning

  • Persist the edges and vertices of the graph in memory and disk (as spill): StorageLevel.MEMORY_AND_DISK
  • Enable Kryo serialization: KryoSerialization.useKryo

Publishing and Releasing

To publish an artifact to the Sonatype/Maven central repository (a snapshot or release), you need to have a Sonatype account, PGP keys and sbt plugins set up. Please follow the sbt guideline for a complete guide to getting started. Once this is done, you can use the sbt-release plugin via the Makefile to publish snapshots and perform releases.

Publishing Snapshots

At any point in the development lifecycle, a snapshot can be published to the central repository.

make publish

Performing a Release

Once development of a version is complete, the artifact should be released to the central repository. This is a two stage process with the artifact first entering a staging repository, followed by a manual promotion process.

make release

After a release to the staging repository, the staging-to-release promotion process must be followed manually before the artifact is available in the central repository.

Versioning

This library aims to adhere to Semantic Versioning 2.0.0. Violations of this scheme should be reported as bugs. Specifically, if a minor or patch version is released that breaks backward compatibility, that version should be immediately removed and/or a new version should be immediately released that restores compatibility. Breaking changes to the public API will only be introduced with new major versions.

Contributing

We welcome contributions by pull requests and bug reports or feature requests as issues.

Authors

Contributors

License

Copyright (c) 2017 SoundCloud Ltd.

See the LICENSE file for details.

spark-pagerank's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spark-pagerank's Issues

Cleanup and remove GraphX APIs

We used to rely on GraphX APIs but since we had so many efficiency problems and bugs, we stopped using GraphX. It's still being used in the GraphUtils though. If we choose to, remove all GraphX APIs and replace with internal case classes and whatnot. We should then have two sets of APIs, one internal to PageRank and one for general graph operations. I like this more since internal to PageRank, we need always tuples (for the joins), while outside of PageRank that makes the RDD's a bit messy with tuples all over the place. Could eventually consider Dataset/DataFrame APIs as well, but for now we stick to functional paradigms with RDDs.

Validate runtimes with production graph

Graph building: 0.2.0, 34 mins, 512 cores, 650M vertices, 14B edges
PageRank run: 0.2.0, 24 mins, 1024 cores, 650M vertices, 14B edges, 5 iterations
PageRank run: 0.2.0, 46 mins, 1024 cores, 650M vertices, 14B edges, 10 iterations

Cleanup GraphUtils

Only general edges/vertices stuff goes in here. Anything operating on the PageRankGraph as a whole should go in PageRankGraph instead.

Use robust checkpointing

Local checkpointing is not robust to executor failures, so we might lose information in the case executors go down and we don't have a redundant cache of lost block(s).

Improve documentation for public consumption

Improve documentation such that it is consumable as an open-source project. This should include any basic rationale about tuning, why or when to use this, examples, dataset sizes we have, etc.

the Vertices value?

Hello!
I have question about the result of the Vertice. the code is in the PageRank.scala file,
for example :

val actual = PageRank.run(
graph, teleportProb,
maxIterations,
convergenceThreshold
).collect()

Does the larger value indicates a stronger importance ?
if I use this value in black list,it indicates that
the person is more dangerous?Is it right?

Don't use object files as app input and outputs

The options are: TSV, CSV, Parquet (or stay with object files). We need some interoperability with other formats in HDFS, like graph building reads from TSV in our case. What should be the standard interface to the apps? You can always build your own apps, the apps are just there for reference, handy usage/testing purposes.

/cc @maxjakob

Rewrite apps to provide better example

This should be couple of apps to both provide real use-case examples as well as for ongoing testing on real-sized graphs:

  • remove hard coded paths
  • show building a graph
  • show running PageRank

Working example/generic usecase

This seems to be great. Can you provide a few lines of code of a working example for this so it becomes easier to use for first-timers.

Thanks for the hep !

Allow drop-in stopping criteria function

Right now we just support iteration number, and convergence as stopping criteria. This could be any function (in theory) including something like APA if the user is only concerned with stopping after the ranks are unchanged between iterations. Consider porting @maxjakob 's APA in here as a plugin option.

Ensure we are using Kryo with custom types

I think without specifying it, we are then just using POJO serialization. Not sure in Spark 2.1.0 how it works so time to check it out. It should also be easy for 3rd party users of our case classes to get this optimization, maybe just documented?

Build a graph from edges and an old priors vector

The cases are:

  • new vertices in the new EdgesRDD that are not in the old VertexRDD
  • vertices missing in the new EdgesRDD that are in the old VertexRDD

These need to be supported if you want to start from disk from a previous VertexRDD with old priors.

Implement missing graph modification functions

For every requirement of the graph structure, there should be a check/validation function as well as a function to correct any structure that needs it. Examples:

  /**
   * Removes any edges that are self-referencing the same vertex. That is, any
   * edges where the source and destination are the same. Any resulting vertices
   * that have no edges (in or out) will remain in the graph.
   */
  def removeSelfReferences(graph: Graph): Graph

  /**
   * Removes any vertices that have no in or out edges.
   */
  def removeDisconnectedVertices(graph: Graph): Graph

Add a graph validation function

This should be stand-alone but can be run on occasion to validate the assumptions and structure of the graph to run PageRank on. This should be a composed function of all the individual tests, and should be a guard function so it can be used in a pipeline.

  /**
   * Validates the structure of the input PageRank graph. See: {{#run}}.
   */
  def validateGraphStructure(edges: Edges, vertices: Vertices) {
    val numSelfReferences = countSelfReferences(graph.edges)
    val verticesAreNormalized = areVerticesNormalized(graph.vertices)
    val numVerticesWithoutNormalizedOutEdges = countVerticesWithoutNormalizedOutEdges(graph.edges)

    require(numSelfReferences == 0, "Number of vertices with self-referencing edges must be 0")
    require(verticesAreNormalized, "Input vertices values must be normalized")
    require(numVerticesWithoutNormalizedOutEdges == 0, "Number of vertices without normalized out edges must be 0")
  }

Add local RDD checkpointing

Add local RDD checkpointing to truncate DAG/parents, after every iteration, this requires that dynamic allocation is off so also validate this at the start of the run by looking in the conf if possible (and document all this in the run function).

Update documentation about double-release bug

When performing a release, since we cross-compile, the first "push changes to repo" should be the only ones. The second time you get asked to tag and push to remote, you should choose to NOT do it since they versions are already updated. Furthermore, you should always make sure to specify the same release version, you will be asked twice (again, once per cross-compile version).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.