Code Monkey home page Code Monkey logo

spark-streaming-with-google-cloud-example's Introduction

Example to Integrate Spark Streaming with Google Cloud at Scale

This is an example to integrate Spark Streaming with Google Cloud products. The streaming application pulls messages from Google Pub/Sub directly without Kafka, using custom receivers. When the streaming application is running, it can get entities from Google Datastore and put ones to Datastore.

What I want to show here is that we can be free from managing some big data products, such as Kafka and Cassandra. We data scientist can focus on implementing logics with Spark Streaming.

Spark Streaming with Google Cloud

Requirments

  • Google Cloud account
    • Need privilege to use Google Pub/Sub topics and subscriptions, Google Datastore and Google Dataproc.
  • Google Cloud SDK
    • version 147.0.0 or later
    • gcloud coomand is required

How to Run

  1. Create Google Pub/Sub topic/subscription
  • gcloud beta pubsub topics create $TOPIC_NAME`
    
  1. Create a Spark cluster on Google Dataproc with make create-dataproc-cluster
  • gcloud dataproc clusters create $CLUSTER_NAME \
        --zone="us-central1-a" \
        --image-version=1.1 \
        --master-machine-type="n1-standard-4" \
        --num-workers=2 \
        --worker-machine-type="n1-standard-4" \
        --scopes=https://www.googleapis.com/auth/pubsub,https://www.googleapis.com/auth/datastore,https://www.googleapis.com/auth/bigquery,https://www.googleapis.com/auth/devstorage.read_write,https://www.googleapis.com/auth/logging.write
    
  1. Create a JAR file of the project
  • make assembly
    
  1. Submit a Spark Streaming job to Google Dataproc
  • ./bin/submit-streaming-job.sh $GOOGLE_PROJECT_ID $PUBSUB_TOPIC
    
  1. Send Pub/Sub messages
  • ./bin/send-pubsub-messages.sh $GOOGLE_PROJECT_ID $PUBSUB_TOPIC
    

Please make sure to delete a Pub/Sub topic and a Dataproc cluster.

Appendix: Price Estimation for Google Pub/Sub and Google Datastore

As you know, Google Cloud Platform Pricing Calculator allows us to estimate how much cost we need to run systems. I would like to show an example cost to use Google Pug/Sub and Google Datastore. Of course, we need extras cost to use Spark Streaming on Google Dataproc.

According to the calculator, the estimated amount is just $22.20 per 1 month. From my perspective, it is much more reasonable than the cost of having an own Kafka cluster and a Cassandra cluster.

The cost was estimated with the following condition:

  • Google Datastore: $16.60
    • Stored data: 50 GB
    • Entity Reads: 10,000,000
    • Entity Writes: 5,000,000
    • Entity Deletes: 1,000,000
  • Cloud Pub/Sub: $6.00
    • Volume of message data: 100 GB

Appendix: How to Avoid Conflicts on protobuf-java Versions

Apache Spark 2.0.2 uses protobuf-java 2.5. Meanwhile, we need to protobuf-java 3.0 or later for Google Datastore. We can't avoid this conflict on protobuf-java event with any eviction.

In stead of any eviction, sbt-assembly offers an excellent feature to resolve this issue. Please take a look ./build.sbt in the repository.

assemblyShadeRules in assembly := Seq(
  ShadeRule.rename("com.google.protobuf.*" -> "shadedproto.@1").inAll
)

Reference

spark-streaming-with-google-cloud-example's People

Contributors

yu-iskw avatar

Watchers

 avatar  avatar

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.