【Azure 應(yīng)用服務(wù)】Azure Function (PowerShell) 執(zhí)行時(shí)報(bào)錯(cuò) "out of memory"

問(wèn)題描述

在Azure Function App服務(wù)中,創(chuàng)建一個(gè)PowerShell腳本的函數(shù),遇見(jiàn)了OOM(Out Of Memory)的異常報(bào)錯(cuò):

2022-01-10T07:44:37  Welcome, you are now connected to log-streaming service. The default timeout is 2 hours. Change the timeout with the App Setting SCM_LOGSTREAM_TIMEOUT (in seconds).
2022-01-10T07:44:39.879 [Information] Executing 'Functions.BlobTrigger1' (Reason='New blob detected: Exception of type 'System.OutOfMemoryException' was thrown.', Id=xxxxxxxx-xxxxxxxx-xxxxxxxx-xxxxxxxx-xxxxxxxx)
2022-01-10T07:44:39.883 [Information] Trigger Details: MessageId: xxxxxxxx-xxxxxxxx-xxxxxxxx-xxxxxxxx-xxxxxxxx, DequeueCount: 5, InsertionTime: 2022-01-10T07:41:29.000+00:00, BlobCreated: 2022-01-10T07:41:28.000+00:00, BlobLastModified: 2022-01-10T07:41:28.000+00:00
2022-01-10T07:44:39.911 [Error] Executed 'Functions.BlobTrigger1' (Failed, Id=xxxxxxxx-xxxxxxxx-xxxxxxxx-xxxxxxxx-xxxxxxxx, Duration=11084ms)Exception of type 'System.OutOfMemoryException' was thrown.

運(yùn)行的腳本就是執(zhí)行 AzCopy Copy 文件

param([byte[]] $InputBlob, $TriggerMetadata)
Write-Host "PowerShell Blob trigger function Processed blob! Name: $($TriggerMetadata.Name) Size: $($InputBlob.Length) bytes"

$AzcoypFile = "azcopy.exe"
$AzCopyExists = Test-Path $AzcoypFile Write-Host "AzCopy exists:" $AzCopyExists
# Download AzCopy.zip and unzip if it doesn't exist
If ($AzCopyExists -eq $False)
{
    Write-Host "AzCopy not found. Downloading..."

    #Download AzCopy
    Invoke-WebRequest -Uri "https://aka.ms/downloadazcopy-v10-windows" -OutFile AzCopy.zip -UseBasicParsing #unzip azcopy
    write-host "unzip azcopy.zip" Expand-Archive ./AzCopy.zip ./AzCopy -Force # Copy AzCopy to current dir
    Get-ChildItem ./AzCopy/*/azcopy.exe | Copy-Item -Destination "./AzCopy.exe" } # Run AzCopy from source blob to destination blob  (Single Direction)
Write-Host "copy new content" ./azcopy.exe sync "https://xxxxx.blob.core.chinacloudapi.cn....."

問(wèn)題分析

因?yàn)槟J(rèn)創(chuàng)建Azure Funciton Windows環(huán)境時(shí),平臺(tái)默認(rèn)使用的是32 Bit,所以存在內(nèi)存上限問(wèn)題。所以最快方法就是查看平臺(tái)的位數(shù),修改為64 Bit。讓系統(tǒng)有更多的內(nèi)存空間可用。

image

參考資料

**I see the message "Worker Process requested recycle due to 'Percent Memory' limit." How do I address this issue? **

https://docs.microsoft.com/en-us/azure/app-service/faq-availability-performance-application-issues#i-see-the-message--worker-process-requested-recycle-due-to--percent-memory--limit---how-do-i-address-this-issue-

The maximum available amount of memory for a 32-bit process (even on a 64-bit operating system) is 2 GB. By default, the worker process is set to 32-bit in App Service (for compatibility with legacy web applications).

Consider switching to 64-bit processes so you can take advantage of the additional memory available in your Web Worker role. This triggers a web app restart, so schedule accordingly.

Also note that a 64-bit environment requires a Basic or Standard service plan. Free and Shared plans always run in a 32-bit environment.

當(dāng)在復(fù)雜的環(huán)境中面臨問(wèn)題,格物之道需:濁而靜之徐清,安以動(dòng)之徐生。 云中,恰是如此!

分類(lèi): 【Azure 應(yīng)用服務(wù)】

標(biāo)簽: App Service, Azure Function, "out of memory", 32 bit or 64 bit

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容