![](/img/trans.png)
[英]Can I sort the items in an Apache beam PCollection using python?
[英]Can I process pcollections in apache beam in chunks? Can I make batches of pcollection and process each batch separately?
我在 GCS 上有大約 2000 個文件,我想處理所有文件並將它們上傳到 BigQuery。 當我使用管道進行處理時,這些管道無法自行完成。 它在處理 70% 的文件后失敗或停止工作。 我決定每批制作 100 個文件。 我使用BatchElements()
在列表中創建了一個列表,即二維列表。 這些批次是否會單獨執行。 意味着第一批的 pcollections 將在第二批開始工作后自行執行(從 GCS 打開文件並將其上傳到 BigQuery)。 這是以串行方式還是並行方式工作? 如果任何批次失敗,我的工作會失敗嗎?
xml = (
p1
| "Get xml name" >> beam.Create(gz_names)
| "Batch elements" >> BatchElements(100)
| "Open file" >> beam.ParDo(ReadGCS())
| "Create XML" >> beam.ParDo(CreateXML())
| "Parse Json" >> beam.ParDo(JsonParser())
| "Remove elements" >> beam.ParDo(Filtering())
| "Build Json" >> beam.ParDo(JsonBuilder())
| "Write elements" >> beam.io.WriteToText(file_path_prefix="output12", file_name_suffix=".json")
)
p1.run()
Beam 和其他大數據系統嘗試執行優化以改善管道的執行。 最簡單的優化稱為“融合”,即
在這種情況下,問題是您的Create
和BatchElements
以及ReadGCS
轉換都在同一個工作人員中執行,並且沒有機會分配給多個工作人員。
我的建議是讓您嘗試重新調整您的數據。 這將使它能夠被重新分配。 像這樣:
xml = (
p1
| "Get xml name" >> beam.Create(gz_names)
| beam.Reshuffle() # This will redistribute your data to other workers
| "Open file" >> beam.ParDo(ReadGCS())
| "Create XML" >> beam.ParDo(CreateXML())
| "Parse Json" >> beam.ParDo(JsonParser())
| "Remove elements" >> beam.ParDo(Filtering())
| "Build Json" >> beam.ParDo(JsonBuilder())
| "Write elements" >> beam.io.WriteToText(file_path_prefix="output12", file_name_suffix=".json")
)
p1.run()
完成此操作后,您的管道應該能夠取得更好的進展。
另一個可以提高管道性能的技巧:考慮使用apache_beam.io.fileio
下的轉換。 它們包括匹配文件名和讀取文件的轉換,它們在 Beam 中是標准的。
如果您想深入了解一些運行器優化,請查看FlumeJava 論文:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.