【Azure 应用服务】Azure Function (PowerShell) 执行时报错 "out of memory"

简介: 【Azure 应用服务】Azure Function (PowerShell) 执行时报错 "out of memory"

问题描述

在Azure Function App服务中,创建一个PowerShell脚本的函数,遇见了OOM(Out Of Memory)的异常报错:

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.

运行的脚本就是执行 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://xxxxxxxxxxxxxxxxx..............

问题分析

因为默认创建Azure Funciton Windows环境时,平台默认使用的是32 Bit,所以存在内存上限问题。所以最快方法就是查看平台的位数,修改为64 Bit。让系统有更多的内存空间可用。

 

 

参考资料

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.

相关文章
|
17天前
【Azure App Service】PowerShell脚本批量添加IP地址到Web App允许访问IP列表中
Web App取消公网访问后,只允许特定IP能访问Web App。需要写一下段PowerShell脚本,批量添加IP到Web App的允许访问IP列表里!
|
28天前
|
Linux Python
【Azure Function】Python Function部署到Azure后报错No module named '_cffi_backend'
ERROR: Error: No module named '_cffi_backend', Cannot find module. Please check the requirements.txt file for the missing module.
|
1月前
|
数据安全/隐私保护
【Azure Entra ID】使用PowerShell脚本导出Entra ID中指定应用下的所有用户信息
在Azure Entra ID中,需要导出一个Application 下的用户信息, 包含User的创建时间。
|
3月前
【Azure Function】Azure Function中的Timer Trigger无法自动触发问题
【Azure Function】Azure Function中的Timer Trigger无法自动触发问题
|
3月前
【Azure Function & Application Insights】在Azure Function的日志中,发现DrainMode mode enabled Traces。它是什么意思呢?
【Azure Function & Application Insights】在Azure Function的日志中,发现DrainMode mode enabled Traces。它是什么意思呢?
|
3月前
|
Python
【Azure Function】发布 Python Function 到 Azure 成功,但是无法显示Function列表
【Azure Function】发布 Python Function 到 Azure 成功,但是无法显示Function列表
|
3月前
|
存储 C# Python
【Azure Storage Account】Azure 存储服务计算Blob的数量和大小的PowerShell代码
【Azure Storage Account】Azure 存储服务计算Blob的数量和大小的PowerShell代码
|
3月前
|
C#
【Azure Function】Function App启动时出现 Failed to open local port 4001 错误,这是什么情况呢?
【Azure Function】Function App启动时出现 Failed to open local port 4001 错误,这是什么情况呢?
|
3月前
|
C# C++
【Azure Function】在VS Code中创建Function项目遇见 No .NET worker runtimes found
【Azure Function】在VS Code中创建Function项目遇见 No .NET worker runtimes found
|
3月前
【Azure Function & Application Insights】调用Function上传和下载文件,有时候遇见大于1MB的文件的日志没有记录在Application Insights中
【Azure Function & Application Insights】调用Function上传和下载文件,有时候遇见大于1MB的文件的日志没有记录在Application Insights中