開發與維運

Cromwell release-49 新特性解析

Task 級別 Callcaching 開關

我們知道,Callcaching是否啟用可以通過如下方式來控制:

  • 配置文件:控制全局的Callcaching 是否開啟
# Optional call-caching configuration.
call-caching {
  # Allows re-use of existing results for jobs you've already run
  # (default: false)
  enabled = true

  # Whether to invalidate a cache result forever if we cannot reuse them. Disable this if you expect some cache copies
  # to fail for external reasons which should not invalidate the cache (e.g. auth differences between users):
  # (default: true)
  invalidate-bad-cache-results = true
}

enabled 設置為 true 時,表示 Callcaching 開啟,反正 Callcaching 關閉。

  • 提交工作流時的option選項
{
  "read_from_cache": true,
  "write_to_cache": true
}

其中 read_from_cache 表示本次工作流的執行是否從 cache 讀取數據,即是否複用之前的運行結果。write_to_cache 表示本次工作流的執行結果是否寫入 cache,即本次運行的結果是否給後面的執行復用。

但在有些場景下,我們需要工作流中的某個指定 task 每次都重新運行,即不使用 Callcaching。使用上面的方式是無法支持的。從 Release-49 版本開始,Cromwell 支持對單個 task 設置是否啟用 Callcaching(官方文檔),下面對這個特性做個介紹。

使用方法

具體來講,我們可以在 task 定義的 meta 部分使用 volatile 來指定當前 task 是否使用 Callcaching,例如:

version 1.0

task make_random_int {

  meta {
    volatile: true
  }

  command <<<
    echo $RANDOM
  >>>

  output {
    Int random = read_string(stdout())
  }
}

volatile 設置為 true 時,表示當前 task 需要重新執行,不啟用 Callcaching。不設置時,默認為false。

其實volatile在計算機編程語言中是個常見的關鍵字,比如在 C/C++/Java 等語言中都有,只不過各自代表的含義不同。例如在C語言中,volatile 關鍵字可以用來提醒編譯器它後面所定義的變量隨時有可能改變,因此編譯後的程序每次需要存儲或讀取這個變量的時候,都會直接從變量地址中讀取數據。如果沒有 volatile 關鍵字,則編譯器可能優化讀取和存儲,可能暫時使用寄存器中的值,如果這個變量由別的程序更新了的話,將出現不一致的現象。

在 WDL 中,volatile的含義和C語言有點類似,表示當前的 task,需要每次都重新執行不要使用 Cache 中的記錄。

中間文件刪除

我們在使用 Cromwell 運行 WDL 的時候可能有這樣的經歷:一個工作流有若干個 task,每個 task 都會產生一定的輸出文件。但是整個 Workflow 的輸出是最後一個 Task 的輸出,也就是說如果工作流運行結束後,只有最後一個 task 的輸出是需要保存的,其他 task 的輸出都屬於中間文件。例如:

task task1 {
  input {
    File file1
    File file2
  }
  command {
    python do_stuff.py ${file2} ${file2}
  }
  output {
    File results = stdout()
  }
}

task task2 {
  input {
    File foobar
  }
  command {
    python do_stuff2.py ${foobar}
  }
  output {
    File results = stdout()
  }
}

workflow wf {
  input {
    File file1
    File file2
  }

  call task1 {
      input: file1 = file1, file2 = file2
  }
  call task2 {
    input: foobar=task1.results
  }

  output {
      File finals = task2.results
  }
}

在上面的例子中,workflow 最終的輸出,只是task2的輸出 results 這一個文件。但在 task1 中我們還產生了 task1.results 這樣一箇中間文件。
如果這些中間文件比較大的話,會佔用較多的存儲空間,不管是線上存儲還是雲上存儲,都意味著成本。

Release-49 版本開始,Cromwell 支持一個 workflow option,來設置工作流運行結束後是否要將中間文件刪除。

使用方法

要使用這個特性,需要配置兩個地方:

  • 全局配置中,設置 delete-workflow-files 開關打開
system {
  # Option to allow Cromwell to delete intermediate output files once the workflow succeeds
  delete-workflow-files = true
}
  • 提交工作流時,在 option 中設置 delete_intermediate_output_files 為 true,表示當前工作流需要刪除中間文件
{
  "delete_intermediate_output_files": true
}

Leave a Reply

Your email address will not be published. Required fields are marked *