資料傳輸效能提升 70%!實測 GCP 的 gcloud storage 與 gsutil 指令的差異

  1. 前言
  2. 什麼是 gsutil 指令?
  3. 什麼是 gcloud 指令?
  4. 官方建議使用 gcloud storage 取代 gsutil
  5. 自行實測結果
    1. 實測環境
    2. 實測結果表
    3. 實測 1:複製一個 249.1 MiB 小型檔案
      1. gsutil cp: 5.4 sec
      2. gcloud storage cp: 3.2 sec ( Speed Up 40% )
    4. 實測 2:複製一個 1.0 GiB 大型檔案
      1. gsutil cp: 24 sec
      2. gcloud storage cp: 6.3 sec ( Speed Up 74% )
  6. 總結
  7. 補充資料

前言

在資料工程師的工作中,常會使用雲端 Google Cloud Platform (GCP) 的 Google Cloud Storage (GCS) 作為 Data Lake 儲存一些非結構化資料,而操作 GCS 的指令我都是用 gsutil 來進行,但近期發現有另一個指令是 gcloud storage ,所以這篇文章記錄我針對這兩種指令實測後發現的差異,以及官方文件的建議。

什麼是 gsutil 指令?

  • gsutil 是一個 Python application,主要用來讓使用者可以透過 Command Line 操作 Cloud Storage,操作包含:
    • Creating and deleting buckets.
    • Uploading, downloading, and deleting objects.
    • Listing buckets and objects.
    • Moving, copying, and renaming objects.
    • Editing object and bucket ACLs.

什麼是 gcloud 指令?

  • gcloud 是 GCP 主要的 CLI 工具,用途更廣不限於 GCS,操作包含:
    • Manages authentication, local configuration and developer workflow.
    • Interactions with the Google Cloud APIs.

官方建議使用 gcloud storage 取代 gsutil

官方已經 不推薦使用 gsutil,一律建議使用 gcloud storage

Should you use gsutil?

Generally, you should use gcloud storage commands instead of gsutil commands:


進到 gsutil 頁面也都會請使用 gcloud storage 的提醒

gsutil is not the recommended CLI for Cloud Storage. Use gcloud storage commands in the Google Cloud CLI instead.


官方實測數據證實,gcloud storage 有顯著的效率提升

When transferring 100 files that were 100MB in size, gcloud storage is 79% faster than gsutil on download and 33% faster on upload.

With a 10GB file, gcloud storage is 94% faster than gsutil on download and 57% faster on upload.


自行實測結果

實測環境

  • 直接利用 GCP Cloud Shell 去執行「複製 GCS Bucket 檔案」的指令
  • 實測的指令都執行二重複,避免結果因短暫的網速或系統狀況影響
  • 採用 Linux 內建的 time 指令來評估,主要看的 output 是 real 的秒數
  • gsutil version:
    • 5.27
  • gcloud version:
    • Google Cloud SDK 475.0.0
    • alpha 2024.05.03
    • core 2024.05.03

實測結果表

檔案大小 \ 平均指令花費時間gsutil cp (sec)gcloud storage cp (sec)gcloud storage
速度提升(%)
小檔案(249 MiB)5.43.6+ 40%
大檔案(1.0 GiB)23.66.3+ 74%

以下是我詳細的實測過程


實測 1:複製一個 249.1 MiB 小型檔案

gsutil cp: 5.4 sec

gcloud storage cp: 3.2 sec ( Speed Up 40% )

實測 2:複製一個 1.0 GiB 大型檔案

gsutil cp: 24 sec

  • throughput: 56 MiB/s

gcloud storage cp: 6.3 sec ( Speed Up 74% )

  • Average throughput: 313.1MiB/s

總結

除了官方的實測外,我個人實測也是 gcloud storage 的效率明顯高出 gsutil 許多,而且複製越大的檔案效率提升越明顯!

指令更改的幅度沒有很大,所以如果是還在使用 gsutil 來操作 GCS 的話,我還滿推薦可以盡快轉換成 gcloud storage,輕鬆無痛提升大約 70% 的 Data Transfer 效率。

這次主要測試了 200 MB 和 1 GB 單一檔案的複製速度,如果是多個超小型檔案的話(例如每個檔案只有 2 KB 之類的),gsutil 使用 -m 參數 (multi-threading/multi-processing) 在 cp 和 rm 的速度是比 gcloud storage 要快的唷!(實測表格可以參考文末補充資料)

所以我個人的總結是

檔案大小在 MB 以上的檔案使用 gcloud storage cp

MB 以下的檔案使用 gsutil -m cp 和 rm

另外要注意的是,有些 gcloud 指令版本可能比較舊,會出現找不到指令的問題,可能要改用 gcloud alpha storage ,雖然是堪用,但我實測上感覺有不少 bug 存在(像是 gcloud alpha storage cp 時資料夾亂掉、gcloud 指令莫名 crashed 等),所以如果是 alpha 版本的話要小心使用~

補充資料

  • 超小型檔案(2 KiB)的複製 (cp) 速度實測
檔案數量 \ 平均指令花費時間gsutil -m cp (sec)gcloud storage cp (sec)
11.92.3
1879.910.5
  • 超小型檔案(2 KiB)的移除 (rm) 速度實測
檔案數量 \ 平均指令花費時間gsutil -m rm (sec)gcloud storage rm (sec)
12.02.4
482.44.4
1873.29.5
5044.621.4
14008.554.4

發表留言