Sean talks

Attitude is everything

0%

[Note] Google Cloud Dataproc

What’s Google Cloud Dataproc ?

dataproc 是 google 推出的 Spark, hadoop 托管服務,可以快速的佈建 cluster 環境,降低管理困難與使用成本,透過 dataproc 用戶可以專注在數據處理與分析上。

此外 dataproc 部署 Spark & hadoop 環境非常的快,同時也可以很好的整合與 BigQuery 、 Cloud Storage 、 Cloud Bigtable 、 Cloud Logging 間的服務。

接下來會說明簡單的建立與工作提交,更多細節參數設定還是需要參照 Dataproc Docs

How to use ?

Create dataproc clusters

建立 clusters 的方式除了透過 GCP 網頁介面也可以透過 gcloud cmd 佈建

1
2
3
gcloud dataproc clusters create \
dataproc-demo \
--region us-west1

更詳細的指令使用可以參照 dataproc creat

SSH into cluster

如同 SSH 至 instance 的方法,可以以 gcloud compute ssh 連線至 VM。

1
2
3
4
gcloud compute ssh \
--zone "us-west1" \
"dataproc-demo" \
--project "sean-demo-project"

Web UI

有時為方邊開發可以透過 --enable-component-gateway 啟用 web interface,
提供 jupyter lab/ MapReduce Job History /YARN Application Timeline 等等功能。
more

Submit a job

以下是提交 pyspark job 的範例,
簡單的示範執行 gcs 中 dataproc-examples bucket 的 ./python/hello-world.py

首先 cp file hello-world.py to bucket

1
gsutil cp ./hello-world.py gs://dataproc-examples/python/hello-world.py

then, submit a pyspark job

1
2
3
4
gcloud dataproc jobs submit pyspark \
--region us-west1 \
--cluster dataproc-demo \
gs://dataproc-examples/python/hello-world.py \

Workflow

Dataproc 同時提供 workflow template API,讓用戶可以很簡單的建立工作排程並管理,
透過建立 .yaml 來設定佈建工作流程。

example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
jobs:
- pysparkJob:
args:
- --name=sean
mainPythonFileUri: gs://dataproc-examples/python/hello-world.py
stepId: dataproc-demo-001
placement:
managedCluster:
clusterName: dataproc-demo
config:
gceClusterConfig:
networkUri: default
zoneUri: us-west1
masterConfig:
diskConfig:
bootDiskSizeGb: 500
bootDiskType: pd-standard
machineTypeUri: n1-standard-4
numInstances: 1
softwareConfig:
imageVersion: 2.0-debian10
properties:
dataproc:dataproc.allow.zero.workers: 'true'

進階使用

Key Points:

  • Instantiating a Workflow Template launches a Workflow. A Workflow is an operation that runs a Directed Acyclic Graph (DAG) of jobs on a cluster. If the workflow uses a managed cluster, it creates the cluster, runs the jobs, and then deletes the cluster when the jobs are finished.
  • If the workflow uses a cluster selector, it runs jobs on a selected existing cluster.
  • Workflows are ideal for complex job flows. You can create job dependencies so that a job starts only after its dependencies complete successfully.
  • Creating a workflow template does not create a Dataproc cluster or submit jobs. Clusters and jobs associated with workflows are created when a workflow template is instantiated.

next

接下來會進一步紀錄 dataproc 搭配 Airflow 進行工作排程的心得與筆記,而什麼是 Airflow 呢?

Airflow 是 Airbnb 開源的 Workflow Management System,閱讀大師寫的 一段 Airflow 與資料工程的故事:談如何用 Python 追漫畫連載 可以深入淺出的了解其用途與佈建開發。

References