SharePoint requests fail when memory is low
Summary
When working in virtual labs, I don't always adhere to best practices. For example, we all know the minimum memory recommendation for SharePoint is 16GB for production use. So, when testing in my labs, SharePoint web requests may fail. As a result, I find myself troubleshooting the issue, only to find the failure was caused by low memory. I have many SharePoint Farms and many VM's for testing, which covers all supported versions. So, one would think I have learned my lesson and simply provision all my virtual machines with at least 16GB's of memory. Well I can't because physical memory on the VM host is not limitless and I can create way more VM's if use less memory.
So why am I telling you this?
Mainly it's for me, so I can find the solution easily when this occurs again (and it will). However, I wanted to share my latest symptom which may help someone in the future.
Issue:
Unable to access a SharePoint site with SharePoint Designer, it was failing with error "The server could not complete your request."
Example:
Clicking on "Details" provided no additional information.
Cause:
Since I kind of spoiled it above, you already know its low memory. By default, when memory is below the 5% of the total memory, "Memory gate checking" at the IIS level kicks in and causes SharePoint failures.
If you think this issue is occurring, look in the application event logs during this failure, you may find the following event.
Log Name: Application
Source: System.ServiceModel 4.0.0.0
Date: 8/10/2018 2:30:15 PM
Event ID: 3
Task Category: WebHost
Level: Error
Keywords: Classic
User: contoso\spservice
Computer: sp
Description:
WebHost failed to process a request.
Sender Information: System.ServiceModel.ServiceHostingEnvironment+HostingManager/56528276
Exception: System.ServiceModel.ServiceActivationException: The service '/b464bf6ac4fd49f986be1900c0ff4950/MetadataWebService.svc' cannot be activated due to an exception during compilation. The exception message is: Memory gates checking failed because the free memory (149831680 bytes) is less than 5% of total memory. As a result, the service will not be available for incoming requests. To resolve this, either reduce the load on the machine or adjust the value of minFreeMemoryPercentageToActivateService on the serviceHostingEnvironment config element.. ---> System.InsufficientMemoryException: Memory gates checking failed because the free memory (149831680 bytes) is less than 5% of total memory. As a result, the service will not be available for incoming requests. To resolve this, either reduce the load on the machine or adjust the value of minFreeMemoryPercentageToActivateService on the serviceHostingEnvironment config element.
at System.ServiceModel.Activation.ServiceMemoryGates.Check(Int32 minFreeMemoryPercentage, Boolean throwOnLowMemory, UInt64& availableMemoryBytes)
at System.ServiceModel.ServiceHostingEnvironment.HostingManager.CheckMemoryCloseIdleServices(EventTraceActivity eventTraceActivity
at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity)
--- End of inner exception stack trace ---
at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity)
at System.ServiceModel.ServiceHostingEnvironment.EnsureServiceAvailableFast(String relativeVirtualPath, EventTraceActivity eventTraceActivity)
Process Name: w3wp
Process ID: 2360
Workaround:
To workaround this issue set the "minFreeMemoryPercentageToActivateService" to "0" in the web.config for the services web application (not the site), which effectively disables "Memory gate checking".
Example:
<system.serviceModel>
<serviceHostingEnvironment minFreeMemoryPercentageToActivateService="0" />
</system.serviceModel>
Steps:
From IIS Manager, right click on the service web app and choose "Explore".
You will see a folder that contains the web.config.
Make a backup copy of the web.config (always a good practice).
Add the "minFreeMemoryPercentageToActivateService" section previously described just above the "</configuration>" closing tag.
Example:
Save the changes and trigger an IISRESET.
Test the changes by accessing Central Admin and a Site Collection.
If all is good, you should be able to continue testing with your new settings.
Disable Memory Checking from a Site Web Application
If your site (not web services) is generating low memory errors, it is possible to disable memory checking at this level as well. However, the web.config may already have a "system.serviceModel" section, so you will need to add the "minFreeMemoryPercentageToActivateService" setting within the current section.
Example:
Before the change:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
After the changes:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" minFreeMemoryPercentageToActivateService="0" />
</system.serviceModel>
Note: Simply add the setting to the current line separated by a space.
Important Takeaways:
- This is not a supported configuration and only should be used for testing functionally in test labs (not performance testing).
- Applying CU's may reverse this setting if web.config changes are present in the update.
- This is an IIS thing and not a SharePoint thing.
- Low memory can occur on production servers as well, even if your server is configured with 16GB's or more.
- Please do not use this setting on a production server, because if your server is running below 5% memory, it needs some attention and not a band-aid.
Comments
- Anonymous
February 06, 2019
Nice :))