【Azure App Service】部署在App Service上的.NET应用内存消耗不能超过2GB的情况分析
问题描述
.Net应用程序部署在App Service for Windows环境中,已经根据需求把Platform的位数由32 bit 修改位 64 bit。 但是应用程序在运行一段时间后,一直抛出Out Of Memory异常。
System.OutOfMemoryException: at System.GC.AllocateNewArray
同时,查看App Service 内存占用指标,才不到2GB。
问题解答
在App Service中,处理要修改Windows 平台为 64外,还需要额外安装 asp.net core runtime x64 version。
默认情况下,x64 dotnet runtime 不会安装在应用服务上。由于在 x64 中运行了应用服务,因此它将请求代理到一个 32 位 dotnet 进程,当请求的内存 >100MB,进程会引发 OutOfMemoryException
解决办法是在App Service门户 Extensions 页面中,安装.NET x runtime x64 版本。安装好扩展插件后,需要重启应用。
- Web App --> Extensions -->"Add" --> 使用 "ASP.NET Core " 关键字过滤
之后,监控App Service 指标,证明内存使用可以达到预期。
参考资料
ASP.NET 6 - Out of Memory Exception on App Service :https://github.com/dotnet/runtime/issues/71014
Cause
x64 dotnet runtime is not installed on the app service by default. Since we had the app service running in x64, it was proxying the request to a 32 bit dotnet process which was throwing an OutOfMemoryException with requests >100MB. It worked on the IaaS servers because we had the x64 runtime installed.Resolution
Installed the ‘ASP.NET Core 5.0 (x64) Runtime’ extension to the app service and restarted the app service.
当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2023-11-14 【Azure APIM】APIM Self-Hosted网关中,添加网关日志以记录请求头信息(Request Header / Response Header)
2022-11-14 【Azure 服务总线】Azure.Messaging.ServiceBus 多次发送消息报超时错误,是否可以配置重新发送?是否有内置重试机制?
2021-11-14 【Azure 环境】用 PowerShell 调用 AAD Token, 以及调用Azure REST API(如资源组列表)