- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个很奇怪的问题;在我们的 REST 应用程序中,我们引入了一个用于上传 WebPackage 的选项。由于这些在解包时可能相当大,我们希望确保通过 MemoryFailPoint 进行内存检查的成功体验。
在我的本地 IIS 7.5 上,这可以完美运行 - 甚至达到最大值。预期值为 2GB。
在我们带有 IIS 7.5 的虚拟 Windows Server 2008R2 x64 上,这会无条件地失败 - 即使只尝试 1MB。
虚拟服务器托管在 VMWare ESXi 4.1.0、348481 上。
以下是在虚拟机上失败的示例代码:
using (MemoryFailPoint failPoint = new MemoryFailPoint(1))
{
... // deliberately excluded webpackage code
}
<InsufficientMemoryException>
<Message>Insufficient memory to meet the expected demands of an operation, and this system is likely to never satisfy this request. If this is a 32 bit system, consider booting in 3 GB mode.</Message>
<StackTrace>
<Line>at System.Runtime.MemoryFailPoint..ctor(Int32 sizeInMegabytes)</Line>
<Line>at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)</Line>
<Line>at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)</Line>
<Line>at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)</Line>
<Line>at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)</Line>
<Line>at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</Line>
</StackTrace>
<UserDefinedInformation>
<failpointSizeInMegaBytes>1.00</failpointSizeInMegaBytes>
<gcTotalMemoryBeforeInMegaBytes>153.34</gcTotalMemoryBeforeInMegaBytes>
</UserDefinedInformation>
</InsufficientMemoryException>
<InsufficientMemoryException>
<Message>Insufficient available memory to meet the expected demands of an operation at this time. Please try again later.</Message>
<StackTrace>
<Line>at System.Runtime.MemoryFailPoint..ctor(Int32 sizeInMegabytes)</Line>
<Line>at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)</Line>
<Line>at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)</Line>
<Line>at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)</Line>
<Line>at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)</Line>
<Line>at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</Line>
</StackTrace>
<UserDefinedInformation>
<failpointSizeInMegaBytes>65536.00</failpointSizeInMegaBytes>
<gcTotalMemoryBeforeInMegaBytes>150.63</gcTotalMemoryBeforeInMegaBytes>
</UserDefinedInformation>
</InsufficientMemoryException>
// Check to see that we both have enough memory on the system
// and that we have enough room within the user section of the
// process's address space. Also, we need to use the GC segment
// size, not the amount of memory the user wants to allocate.
// Consider correcting this to reflect free memory within the GC
// heap, and to check both the normal & large object heaps.
ulong num1 = (ulong) sizeInMegabytes << 20;
this._reservedMemory = num1;
ulong size = (ulong)(Math.Ceiling((double)num1 / (double)MemoryFailPoint.GCSegmentSize) * (double)MemoryFailPoint.GCSegmentSize);
if (size >= MemoryFailPoint.TopOfMemory)
throw new InsufficientMemoryException(Environment.GetResourceString("InsufficientMemory_MemFailPoint_TooBig"));
Process Name: w3wp
PID: 5716
User Name: NT AUTHORITY\NETWORK SERVICE
Working Set: 376.456 K
Peak Working Set: 432.400 K
Private Working Set: 320.684 K
Commit Size: 538.552 K
Handles: 919
Threads: 39
BootDevice: \Device\HarddiskVolume1
BuildNumber: 7601
BuildType: Multiprocessor Free
Caption: Microsoft Windows Server 2008 R2 Standard
CodeSet: 1252
CountryCode: 45
CreationClassName: Win32_OperatingSystem
CSCreationClassName: Win32_ComputerSystem
CSDVersion: Service Pack 1
CSName: SOME_NAME [MODIFIED]
CurrentTimeZone: 120
DataExecutionPrevention_32BitApplications: True
DataExecutionPrevention_Available: True
DataExecutionPrevention_Drivers: True
DataExecutionPrevention_SupportPolicy: 3
Debug: False
Description: Development Server
Distributed: False
EncryptionLevel: 256
ForegroundApplicationBoost: 2
FreePhysicalMemory: 5.366.516 K
FreeSpaceInPagingFiles: 8.368.456 K
FreeVirtualMemory: 12.985.412 K
InstallDate: 17-01-2011 15:01:55
LargeSystemCache: null
LastBootUpTime: 11-09-2012 14:44:33
LocalDateTime: 03-10-2012 14:13:47
Locale: 0406
Manufacturer: Microsoft Corporation
MaxNumberOfProcesses: 4294967295
MaxProcessMemorySize: 8.589.934.464 K
MUILanguages: System.Object[]
Name: Microsoft Windows Server 2008 R2 Standard |C:\Windows|\Device\Harddisk0\Partition2
NumberOfLicensedUsers: null
NumberOfProcesses: 70
NumberOfUsers: 7
OperatingSystemSKU: 7
Organization:
OSArchitecture: 64-bit
OSLanguage: 1033
OSProductSuite: 272
OSType: 18
OtherTypeDescription: null
PAEEnabled: null
PlusProductID: null
PlusVersionNumber: null
Primary: True
ProductType: 3
RegisteredUser: Windows User
SerialNumber: 11111-111-1111111-11111 [MODIFIED]
ServicePackMajorVersion: 1
ServicePackMinorVersion: 0
SizeStoredInPagingFiles: 8.388.152 K
Status: OK
SuiteMask: 272
SystemDevice: \Device\HarddiskVolume2
SystemDirectory: C:\Windows\system32
SystemDrive: C:
TotalSwapSpaceSize: null
TotalVirtualMemorySize: 16.774.452 K
TotalVisibleMemorySize: 8.388.152 K
Version: 6.1.7601
WindowsDirectory: C:\Windows
最佳答案
.net 4.5 和 IIS 中存在错误(或功能)。
MemoryFailPoint 类依赖于一个内部 GC 相关变量,但在 x64 下,此变量可以为 0,除以零可以生成正无穷大(double),并且使用此极值的某些操作(甚至与零相乘)可以生成很大的 double 值(取决于实际的 FPU 设置)。
你可以很容易地检查这个错误。
创建一个简单的 Web 应用程序并添加一个页面,然后粘贴以下代码:
<%
var memoryFailPointType = typeof(System.Runtime.MemoryFailPoint);
var staticPrivateFieldFlags =
System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Static;
var gCSegmentSizeField = memoryFailPointType
.GetField("GCSegmentSize", staticPrivateFieldFlags);
var gCSegmentSize = (uint)gCSegmentSizeField.GetValue(null);
string allocationResult;
try
{
using (var mfp = new System.Runtime.MemoryFailPoint(1))
{
allocationResult = "Ok";
}
}
catch (Exception exception)
{
allocationResult = exception.Message;
}
%>
<%= gCSegmentSize %><br /> <!-- it can be 0 -->
<%= allocationResult %><br /> <!-- Insufficient memory to meet the expected demands of an operation, and this system is likely to never satisfy this request. If this is a 32 bit system, consider booting in 3 GB mode. -->
关于.net - MemoryFailPoint 无条件抛出 InsufficientMemoryException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12707970/
A MemoryFailPoint (MSDN) “在执行操作之前检查是否有足够的内存资源。” 但它究竟是如何正确使用的呢? MemoryFailPoint 是否会自动为我创建的下一个大对象保留一些内
我有一个很奇怪的问题;在我们的 REST 应用程序中,我们引入了一个用于上传 WebPackage 的选项。由于这些在解包时可能相当大,我们希望确保通过 MemoryFailPoint 进行内存检查的
我写了下面的代码来检查内存是否充足, while (true) { try { // Check for available memory. memFa
我创建了一个具有自组织内存管理的卷类(称为 VoxelVolume),因为 C# 中的 GC 没有提供良好的机制来管理映射、取消映射和重新映射的卷内容。虽然我可以使用虚拟内存机制,但问题是文件通常太大
我是一名优秀的程序员,十分优秀!