機器學習

How Smart Tools Are Shaping the Future of Creative Work

Eric Chuang
2021-06-17

Dataflow

開始 Lab 以前,需要先確認自己的專案 {project-number}[email protected] 是否有編輯者 (Editor) 的權限。

確認後,建立 Cloud Storage 貯體。

安裝 pip 與 Cloud Dataflow SDK

開啟 Cloud Shell,檢查 Python 版本。

python3 --version
# 檢查 pip 版本
pip3 --version
# 更新 pip 至最新版本
sudo pip3 install -U pip
# 安裝虛擬環境套件
sudo pip3 install --upgrade virtualenv
# 建立 pip 虛擬環境 Virtual Environment
virtualenv -p python3.7 env
# 啟用虛擬環境
source env/bin/activate

進入虛擬環境後,Shell 前面會多一個 (env) 標示。接著安裝 Apache Beam for Python。

pip install apache-beam[gcp]

接著執行 wordcount.py 程式。將 OUTPUT_FILE 變更為想要輸出的檔案名稱。

python -m apache_beam.examples.wordcount --output OUTPUT_FILE

執行完畢後便可以看到路徑中產生 OUTPUT_FILE 的檔案。用 cat 檢查檔案內容

# 確認完整檔案名稱
ls
cat 檔案名稱

在遠端執行

首先,先定義 Cloud Storage 貯體。

BUCKET=gs://<bucket name provided earlier>

接著執行以下指令,在遠端執行 wordcount.py。

python -m apache_beam.examples.wordcount --project $DEVSHELL_PROJECT_ID \
  --runner DataflowRunner \
  --staging_location $BUCKET/staging \
  --temp_location $BUCKET/temp \
  --output $BUCKET/results/output \
  --region us-central1

點選導覽選單 > [Dataflow] > [Jobs],檢查執行狀況。等到執行完成時,會回傳 Succeeded。

接著到 Cloud Storage 貯體中的 results 路徑檢視執行結果。

Dataproc – Command Line

  1. 建立名為 example-cluster 的 Dataproc 叢集。
  2. 送出任務,執行 pi 的計算。
gcloud config set dataproc/region us-central1
gcloud dataproc clusters create example-cluster --worker-boot-disk-size 500

gcloud dataproc jobs submit spark --cluster example-cluster \
  --class org.apache.spark.examples.SparkPi \
  --jars file:///usr/lib/spark/examples/jars/spark-examples.jar -- 1000

其他更新叢集的指令

利用 --num-workers 可以調整背景工作數量。

gcloud dataproc clusters update example-cluster --num-workers 4

Sign up for our newsletter

Subscribe to our newsletter to receive the latest updates, expert insights, and practical tips directly in your inbox. Stay informed with content designed to help you grow.

+480.000 happy customers

Gain more with expert solutions

Unlock the full potential of your business with our expert solutions. Our team provides tailored strategies, professional guidance, and actionable insights to help you achieve better results.

  • Eric Chuang
  • •
  • 2025-01-23
如何同時使用 Webinoly 與 Cloudflare 保護網站安全

在社群夥伴勇哥的文章〈Webinoly 最新版快速安裝〉中,提到使用 Webinoly 來建立 WordPre […]

主機