[英]Memory issues in a Cloud Storage Function
我已經部署了一個存儲觸發器雲 function,它需要更多 memory。在部署 GCF 時,我已經通過以下方式使用適當的標志進行了部署。
gcloud functions deploy GCF_name--runtime python37 --trigger-resource bucket_name --trigger-event google.storage.object.finalize --timeout 540s --memory 8192MB
但我在谷歌雲控制台中觀察到,memory 利用率 map 不會超過 2GB。 在日志中,我收到此錯誤, Function execution took 34566 ms, finished with status: 'connection error'
,這是由於 memory 短缺而發生的。 我能得到一些幫助嗎?
已編輯
該應用程序將文本文件上傳到包含一定數量樣本的存儲中。 每個文件在上傳到存儲時都會被讀取,並且數據會附加到預先存在的文件中。 樣本總數最多為 75600002。這就是我需要 8GB 數據的原因。 它在將數據附加到文件時出現連接錯誤。
def write_to_file(filename,data,write_meta = False,metadata = []):
file1 = open('/tmp/'+ filename,"a+")
if write_meta:
file1.write(":".join(metadata))
file1.write('\n')
file1.write(",".join(data.astype(str)))
file1.close()
每次上傳后 memory 利用率 map 都是一樣的。
您正在將文件寫入內存文件系統/tmp
。 因此,請在完成上傳后刪除該文件。 事實上那些:
您編寫的文件消耗 memory 可用於您的 function,並且有時在兩次調用之間持續存在。 未能顯式刪除這些文件可能最終導致內存不足錯誤和隨后的冷啟動。
參考: https://cloud.google.com/functions/docs/bestpractices/tips#always_delete_temporary_files
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.