我有一个已发布的WCF(C#)项目,遇到了“OutOfMemoryException”问题。DLL是使用“Any CPU”构建的,AppPool内存设置为0(表示没有限制)。
我每分钟持续处理大约1500个请求和其他大约100个请求。该项目使用EntityFramework。应用程序中有缓存(它是一个字典)。
我进行了一些故障排除以尝试找出问题,但目前还不清楚。我尝试计算总内存使用量(通过调用“GC.GetTotalMemory(false)”)和缓存列表的大小。在获取OOM异常时,缓存大小约为7 MB(30 KB每个对象2500个),而总内存使用量在600 MB到1.5 GB之间变化。
因此,很明显内存并没有满,资源也会被
主要看到日志中在将对象序列化为JSON(我使用Newtonsoft)或对字符串执行某些操作(连接,替换,Regexreplace等)时发生OOM异常,以下是一些异常示例:
有什么想法或建议可以用来复现问题吗?
我进行了一些故障排除以尝试找出问题,但目前还不清楚。我尝试计算总内存使用量(通过调用“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)
有什么想法或建议可以用来复现问题吗?