我有一个WCF(C#)项目发布,并面临“OutOfMemoryException”问题。这些DLL使用Any CPU
构建。 AppPool内存设置被设置为0(表示没有限制)。 我每分钟有大约1500个请求,并且每分钟有大约100个其他请求。该项目使用EntityFramework。有应用程序缓存(这是一个字典)OutOfMemoryException - WCF服务
我做了一些故障排除,试图找出问题,但目前尚不清楚。我尝试计算使用的总内存(通过调用GC.GetTotalMemory(false)
)和缓存列表的大小。在获得OOM例外时,高速缓存大小约为7 MB(每个30 KB的2500个对象),并且使用的总内存在600 MB到1.5 GB之间变化。
因此很明显内存不足并且资源被GarbageCollector
定期清除(内存大小不会一直增加)。因此,OOM异常并不是因为内存已满。
主要是在将对象序列化为JSON(我正在使用Newtonsoft)或对字符串应用某些操作(连接,替换,Regexreplace,...)时,在日志中看到OOM异常,下面是异常的一些示例:
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
at System.Text.StringBuilder.ExpandByABlock(Int32 minBlockCharCount)
at System.Text.StringBuilder.Append(Char* value, Int32 valueCount)
at System.Text.StringBuilder.Append(String value, Int32 startIndex, Int32 count)
at System.Text.RegularExpressions.RegexReplacement.Replace(Regex regex, String input, Int32 count, Int32 startat)
at System.Text.RegularExpressions.Regex.Replace(String input, String replacement, Int32 count, Int32 startat)
at System.Text.RegularExpressions.Regex.Replace(String input, String replacement)
at System.Text.RegularExpressions.Regex.Replace(String input, String pattern, String replacement)
和
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
at System.String.ReplaceInternal(String oldValue, String newValue)
at System.String.Replace(String oldValue, String newValue)
什么可以做,以重现该问题的任何意见或建议?
验证过程的位数。你会发现它是32位的。 – usr
我该如何获得比特?该DLL使用“任何CPU”设置构建,并且服务器运行Windows Server 2012 x64。所以DLL的正常行为是64! – Mostafa
DLL承担主机进程的位数。使用Process Explorer找出或Response.Write(IntPtr.Size)。 – usr