我正在使用服务使用的数据库运行 Sql Server 2008 R2 Express。数据库在服务启动时通过 AttachDBFileName 选项附加。该服务不断运行并仅在自动更新后重新启动。
有时,这种模式会出现在 Sql Server 日志中:
10/09/2013 11:18:05,spid18s,Unknown,AppDomain 6 (..MDF.dbo[runtime].5) unloaded.
10/09/2013 11:18:05,spid1s,Unknown,AppDomain 6 (...MDF.dbo[runtime].5) is marked for unload due to memory pressure.
10/09/2013 11:16:16,spid53,Unknown,AppDomain 6 (....MDF.dbo[runtime].5) created.
10/09/2013 11:16:00,spid28s,Unknown,AppDomain 5 (....MDF.dbo[runtime].4) unloaded.
10/09/2013 11:16:00,spid1s,Unknown,AppDomain 5 (....MDF.dbo[runtime].4) is marked for unload due to memory pressure.
10/09/2013 11:15:41,spid53,Unknown,AppDomain 5 (...MDF.dbo[runtime].4) created.
10/09/2013 11:14:20,spid24s,Unknown,AppDomain 4 (...MDF.dbo[runtime].3) unloaded.
10/09/2013 11:14:20,spid1s,Unknown,AppDomain 4 (...MDF.dbo[runtime].3) is marked for unload due to memory pressure.
这会导致性能问题,因为每次重新启动 AppDomain 时,都会删除缓冲区并且数据库会在几秒钟内无响应。
根据http://support.microsoft.com/kb/917271?wa=wsignin1.0,这可能是由于 CLR 模块中的内存泄漏或其他错误(即使我认为应该在 Sql Server 2008 R2 中修复) . 安装了一个 CLR 模块,代码如下:
[Serializable]
[Microsoft.SqlServer.Server.SqlUserDefinedAggregate(Format.UserDefined,
MaxByteSize=8000)]
public class Concatenate : IBinarySerialize
{
/// <summary>
/// The variable that holds the intermediate result of the concatenation
/// </summary>
private StringBuilder intermediateResult;
public void Init()
{
// Put your code here
intermediateResult = new StringBuilder();
}
public void Accumulate(SqlString Value)
{
if (Value.IsNull)
return;
intermediateResult.Append(Value.Value).Append(", ");
}
public void Merge(Concatenate Group)
{
intermediateResult.Append(Group.intermediateResult);
}
public SqlString Terminate()
{
string output = string.Empty;
//delete the trailing comma, if any
if (intermediateResult != null && intermediateResult.Length > 0)
output = intermediateResult.ToString(0, intermediateResult.Length - 2);
return new SqlString(output);
}
#region IBinarySerialize Members
public void Read(System.IO.BinaryReader r)
{
if (r == null) throw new ArgumentNullException("r");
intermediateResult = new StringBuilder(r.ReadString());
}
public void Write(System.IO.BinaryWriter w)
{
if (w == null) throw new ArgumentNullException("w");
w.Write(intermediateResult.ToString());
}
#endregion
}
此外,MS Exchange 正在服务器上运行,使用了 90% 的可用内存用于 MDB 存储。但是我过去在其他具有大量可用内存的服务器上看到了这个错误,所以我认为内存压力不是问题的真正原因。
有什么想法可能导致这个问题吗?