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 這樣一個中間檔案。
如果這些中間檔案比較大的話,會占用較多的存儲空間,不管是線上存儲還是雲上存儲,都意味着成本。
從
版本開始,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
}