Dataflow 工作圖表

Dataflow 監控介面會提供每個工作的圖示,也就是「工作圖」。工作圖也會提供工作摘要、工作記錄,以及管道中每個步驟的相關資訊。

如要查看工作的作業圖,請執行下列步驟:

  1. 在 Google Cloud 控制台中,依序前往「Dataflow」>「Jobs」(工作) 頁面。

    前往「Jobs」(工作) 頁面

  2. 選取職務。

  3. 按一下「Job graph」(工作圖表) 分頁標籤。

根據預設,作業圖表頁面會顯示「圖表檢視」。如要以表格形式查看工作圖表,請在「工作步驟檢視畫面」中選取「表格檢視畫面」。表格檢視畫面會以不同格式顯示相同資訊。表格檢視在下列情況中很有幫助:

  • 您的工作有許多階段,因此工作圖難以瀏覽。
  • 您想依特定屬性排序工作步驟。舉例來說,您可以依實際時間排序表格,找出速度緩慢的步驟。

圖表檢視

作業圖會以方塊表示管道中的各項轉換,下圖顯示含有三項轉換的作業圖:Read PubSub Events5m WindowWrite File(s)

監控 UI 中工作圖的螢幕截圖

每個方塊都包含下列資訊:

  • 轉換名稱

  • 狀態;下列其中一項:

    • 「Running」(執行中):這個步驟正在執行。
    • 「Queued」(已排入佇列):FlexRS 工作中的步驟已排入佇列
    • Succeeded (成功):這個步驟已順利完成
    • Stopped (已停止):工作已停止,因此這個步驟已停止
    • Unknown (不明):這個步驟無法回報狀態
    • 「Failed」(失敗):這個步驟無法完成
  • 資料延遲

  • 實際時間

  • 最長作業延遲時間

  • 執行這個步驟的工作階段數量

如果步驟代表複合式轉換,您可以展開步驟來查看子轉換。如要展開步驟,請按一下「展開節點」箭頭。

轉換名稱

Dataflow 可透過幾種不同方式取得監控工作圖中顯示的轉換名稱。轉換名稱會顯示在公開位置,包括 Dataflow 監控介面、記錄檔和偵錯工具。請勿使用包含個人識別資訊的轉換名稱,例如使用者名稱或機構名稱。

Java

  • Dataflow 可使用您套用轉換時指派的名稱。您提供給 apply 方法的第一個引數是轉換名稱。
  • Dataflow 可推論轉換的名稱,即根據類別名稱 (如果您建構了自訂轉換) 或 DoFn 函式物件名稱 (如果您使用 ParDo 等核心轉換) 來推論轉換的名稱。

Python

  • Dataflow 可使用您套用轉換時指派的名稱。您可指定轉換的 label 引數,藉此設定轉換名稱。
  • Dataflow 可推論轉換的名稱,即根據類別名稱 (如果您建構了自訂轉換) 或 DoFn 函式物件名稱 (如果您使用 ParDo 等核心轉換) 來推論轉換的名稱。

Go

  • Dataflow 可使用您套用轉換時指派的名稱。您可指定 Scope,藉此設定轉換名稱。
  • Dataflow 可推論轉換的名稱,即根據結構體名稱 (如果您使用結構性 DoFn) 或函式名稱 (如果您使用函式 DoFn) 來推論轉換的名稱。

查看步驟資訊

按一下工作圖中的步驟,「步驟資訊」面板會顯示該步驟的詳細資料。詳情請參閱工作步驟資訊

瓶頸

如果 Dataflow 偵測到瓶頸,工作圖會顯示受影響步驟的警示符號。如要查看瓶頸原因,請按一下步驟開啟「Step Info」(步驟資訊) 面板。詳情請參閱「排解效能瓶頸」。

兩個工作步驟,並有瓶頸警報

工作圖表範例

本節會顯示一些管道程式碼範例,以及對應的工作圖表。

基本工作圖表

管道程式碼:

Java

  // Read the lines of the input text.
  p.apply("ReadLines", TextIO.read().from(options.getInputFile()))
     // Count the words.
     .apply(new CountWords())
     // Write the formatted word counts to output.
     .apply("WriteCounts", TextIO.write().to(options.getOutput()));

Python

(
    pipeline
    # Read the lines of the input text.
    | 'ReadLines' >> beam.io.ReadFromText(args.input_file)
    # Count the words.
    | CountWords()
    # Write the formatted word counts to output.
    | 'WriteCounts' >> beam.io.WriteToText(args.output_path))

Go

  // Create the pipeline.
  p := beam.NewPipeline()
    s := p.Root()
  // Read the lines of the input text.
  lines := textio.Read(s, *input)
  // Count the words.
  counted := beam.ParDo(s, CountWords, lines)
  // Write the formatted word counts to output.
  textio.Write(s, *output, formatted)
工作圖表:

Dataflow 監控介面中顯示的 WordCount 管道執行圖。

圖 1:WordCount 管道的管道程式碼,與產生的執行圖並列顯示在 Dataflow 監控介面中。

含有複合轉換作業的工作圖

複合轉換是指包含多個巢狀子轉換的轉換。在工作圖中,複合式轉換可展開。如要展開轉換並查看子轉換,請按一下箭頭。

管道程式碼:

Java

  // The CountWords Composite Transform
  // inside the WordCount pipeline.

  public static class CountWords
    extends PTransform<PCollection<String>, PCollection<String>> {

    @Override
    public PCollection<String> apply(PCollection<String> lines) {

      // Convert lines of text into individual words.
      PCollection<String> words = lines.apply(
        ParDo.of(new ExtractWordsFn()));

      // Count the number of times each word occurs.
      PCollection<KV<String, Long>> wordCounts =
        words.apply(Count.<String>perElement());

      return wordCounts;
    }
  }

Python

# The CountWords Composite Transform inside the WordCount pipeline.
@beam.ptransform_fn
def CountWords(pcoll):
  return (
      pcoll
      # Convert lines of text into individual words.
      | 'ExtractWords' >> beam.ParDo(ExtractWordsFn())
      # Count the number of times each word occurs.
      | beam.combiners.Count.PerElement()
      # Format each word and count into a printable string.
      | 'FormatCounts' >> beam.ParDo(FormatCountsFn()))

Go

  // The CountWords Composite Transform inside the WordCount pipeline.
  func CountWords(s beam.Scope, lines beam.PCollection) beam.PCollection {
    s = s.Scope("CountWords")

    // Convert lines of text into individual words.
    col := beam.ParDo(s, &extractFn{SmallWordLength: *smallWordLength}, lines)

    // Count the number of times each word occurs.
    return stats.Count(s, col)
  }
工作圖表:

WordCount 管道的作業圖,管道的 CountWords 轉換已展開,顯示其中的子轉換。

圖 2:CountWords 轉換子步驟的管道程式碼。顯示整個管道的已展開工作圖。

在管道程式碼中,您可能會使用下列程式碼叫用複合轉換:

result = transform.apply(input);

以這種方式叫用的複合轉換會省略預期的巢狀結構,因此可能會在 Dataflow 監控介面中顯示為展開狀態。在執行管道時,您的管道也可能會產生有關穩定專屬名稱的警告或錯誤。

如要避免這些問題,請使用建議的格式叫用轉換作業:

result = input.apply(transform);

後續步驟