Description of the problem
When creating an App Service service, the maximum memory usage varies depending on the pricing tier. However, in actual testing, it was found that the maximum memory usage was only about 2GB, the
While the memory allocation in the pricing tier is clearly greater than 2GB (e.g., 7GB in the B3 pricing tier), what is the situation?
On the Kudu tool in App Service, view the size of the memory allocated by the process:
Problem solving
Validation is performed using a short piece of C# code that is a loop that creates multiple 100MB sized objects based on the number entered in the URL.
var builder = (args); // Add services to the container. var app = (); ("/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 per object } return "Successfully created large array object." + objs; } catch (OutOfMemoryException) { return "Insufficient memory to create large array objects"; } }); ();
The code is debugged locally and you can see that the app's memory usage has skyrocketed:
After deploying to Azure App Service, also through the Kudu site Process information, it was found that the memory usage is indeed only about 2GB, but the page returns when the request requires more memory resources:Insufficient memory to create large array objects
This is because App Service for Windows uses a 32-bit operating system by default and can only allocate a maximum of 2GB of memory.
When actively modified bit 64-bit, App Service memory can be occupied to the maximum allowed by the pricing tier!
If B3's pricing layer is viewed in Kudu, the process allocates up to 6GB of memory
Based on the above quiz, when the expected value is not reached using App Service memory and the application exception log shows OutOfMemory, it is necessary to check whether the Platform setting is bit 64bit.
bibliography
I see the message "Worker Process requested recycle due to 'Percent Memory' limit." How do I address this issue?
/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.