【Azure App Service】在App Service for Windows上验证能占用的内存最大值

简介: 根据以上测验,当使用App Service内存没有达到预期的值,且应用异常日志出现OutOfMemory时,就需要检查Platform的设置是否位64bit。

问题描述

在创建App Service服务的时候,根据定价层不同,内存使用的最大值也有不同。但在实际测试中,发现内存最大只能占用2GB左右,

而定价层中内存分配明明是大于2GB(比如B3定价层的内存为7GB), 这是一种什么情况呢?

在App Service中Kudu工具上,查看进程分配的内存大小:

 

问题解答


使用一段简短C#代码来进行验证,代码是一个循环,根据URL中输入的数字,循环创建多个100MB大小的对象.

var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
var app = builder.Build();

app.MapGet("/oom/{objs}", (string objs) =>
{
    int objunmbers = int.Parse(objs);
    try
    {
        byte[][] largeArray = new byte[objunmbers][];
        for (int i = 0; i < objunmbers; i++)
        {
            largeArray[i] = new byte[1024 * 1024 * 100]; // 每个对象占用100MB
        }
        return "成功创建大数组对象: " + objs;
    }
    catch (OutOfMemoryException)
    {
        return "内存不足,无法创建大数组对象";
    }
});

app.Run();


代码本地调试,可以看见应用占用内存直线上涨:

部署到Azure App Service后,同样通过Kudu站点Process信息,发现内存的占用的确只有2GB左右,但请求需要更多内存资源时,页面返回:内存不足,无法创建大数组对象

这是因为App Service for Windows默认使用32位操作系统,最大内存只能分配2GB。

当主动修改位64位后,App Service 内存就可以占用到定价层所允许的最大值!

如B3的定价层在Kudu中查看到w3wp.exe进程分配的内存达到了6GB

 

根据以上测验,当使用App Service内存没有达到预期的值,且应用异常日志出现OutOfMemory时,就需要检查Platform的设置是否位64bit。

 

参考资料

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

https://learn.microsoft.com/en-us/troubleshoot/azure/app-service/web-apps-performance-faqs#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.

 



当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!

相关文章
|
11月前
|
小程序
【04】微信支付商户申请下户到配置完整流程-微信开放平台移动APP应用通过-微信商户继续申请-微信开户函-视频声明-以及对公打款验证-申请+配置完整流程-优雅草卓伊凡
【04】微信支付商户申请下户到配置完整流程-微信开放平台移动APP应用通过-微信商户继续申请-微信开户函-视频声明-以及对公打款验证-申请+配置完整流程-优雅草卓伊凡
768 1
【04】微信支付商户申请下户到配置完整流程-微信开放平台移动APP应用通过-微信商户继续申请-微信开户函-视频声明-以及对公打款验证-申请+配置完整流程-优雅草卓伊凡
|
安全 Windows
【Azure Cloud Service】在Windows系统中抓取网络包 ( 不需要另外安全抓包工具)
通常,在生产环境中,为了保证系统环境的安全和纯粹,是不建议安装其它软件或排查工具(如果可以安装,也是需要走审批流程)。 本文将介绍一种,不用安装Wireshark / tcpdump 等工具,使用Windows系统自带的 netsh trace 命令来获取网络包的步骤
343 32
|
开发框架 监控 .NET
【Azure App Service】部署在App Service上的.NET应用内存消耗不能超过2GB的情况分析
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 install
312 5
|
弹性计算 关系型数据库 数据安全/隐私保护
阿里云国际版如何配置Windows服务器的虚拟内存
阿里云国际版如何配置Windows服务器的虚拟内存
|
C# 开发工具 Windows
C# 获取Windows系统信息以及CPU、内存和磁盘使用情况
C# 获取Windows系统信息以及CPU、内存和磁盘使用情况
591 0
|
Windows C#
Windows Service的安装卸载 和 Service控制
原文 Windows Service的安装卸载 和 Service控制 本文内容包括如何通过C#代码安装Windows Service(exe文件,并非打包后的安装文件)、判断Service是否存在、获得Service状态及启动停止Service。
1048 0
|
4月前
|
安全 数据安全/隐私保护 虚拟化
Windows Server 2022 中文版、英文版下载 (2025 年 10 月更新)
Windows Server 2022 中文版、英文版下载 (2025 年 10 月更新)
1091 2
Windows Server 2022 中文版、英文版下载 (2025 年 10 月更新)
|
4月前
|
安全 Unix 物联网
Windows 7 & Windows Server 2008 R2 简体中文版下载 (2025 年 10 月更新)
Windows 7 & Windows Server 2008 R2 简体中文版下载 (2025 年 10 月更新)
486 0
Windows 7 & Windows Server 2008 R2 简体中文版下载 (2025 年 10 月更新)
|
4月前
|
存储 SQL 人工智能
Windows Server 2025 中文版、英文版下载 (2025 年 10 月更新)
Windows Server 2025 中文版、英文版下载 (2025 年 10 月更新)
685 0
|
5月前
|
运维 安全 网络安全
Windows Server 2019拨号“找不到设备”?Error 1058解决指南
Windows Server 2019拨号报错1058?别急!这不是硬件故障,而是关键服务被禁用。通过“服务依存关系”排查,依次启动“安全套接字隧道协议”“远程接入连接管理”和“路由与远程访问”服务,仅需4步即可恢复PPPoE或VPN拨号功能,轻松解决网络中断问题。
434 1

热门文章

最新文章