我们已将网站托管到亚马逊。其中一个网站用于动态提供图像。完成大量操作,创建内存流和所有...
系统表现得很奇怪..它工作正常一段时间,然后下车一段时间......等等。
没有特定的图片网址集,因为它可能表现不佳。它随机而来。
我附加了一个性能监视器,我跟踪它以查看可能存在的问题,我的猜测是,可能是由于某些非托管内存问题。 四个过滤器是:
Process\Private Bytes
.NET CLR Memory# Bytes in all Heaps
Process\Working Set
.NET CLR Memory\Large Object Heap size
public MemoryStream FetchImageStream(string directoryType, string folderName, string imageName, AmazonS3 clientS3)
{
var msImage = new MemoryStream();
string s3Key = Data.GetS3Key(directoryType, folderName, imageName);
//Get the image path append with the image name.
try
{
GetObjectResponse getObjectResponse = clientS3.GetObject(new GetObjectRequest
{
BucketName = Constants.Bucket,
//set the root images folder name(It is similar to a root folder in Windows).
Key = s3Key, //Set the image path
Timeout = Constants.Timeout.CastInteger() //Set the milliseconds for the time out
});
using (var bufferedStream = new BufferedStream(getObjectResponse.ResponseStream))
//Buffer the image stream from get object response
{
var buffer = new byte[0x3000];
int count;
while ((count = bufferedStream.Read(buffer, 0, buffer.Length)) > 0)
{
msImage.Write(buffer, 0, count); // Write the image into memory stream
}
}
getObjectResponse.Dispose();
}
catch (AmazonS3Exception ex)
{
Data.LogError(ex, "FetchImageStream", string.Empty, string.Empty, folderName, imageName);
}
catch (Exception ex)
{
Data.LogError(ex, "FetchImageStream", string.Empty, string.Empty, folderName, imageName);
}
return msImage;
}
这个问题的大部分错误都是:
无法从传输连接读取数据:通过调用WSACancelBlockingCall中断阻塞操作。
请求已中止:请求已取消。
Stream不支持阅读。
计算最后一次perfmon的平均最小值
操作已经超时。
请告诉我一些可能出错的问题,或者我们如何跟踪这个?
答案 0 :(得分:2)
您应该注意两件事:
getObjectResponse.Dispose();
行,导致内存泄漏。使用using
语句或finally
块(无论如何都与IL相同)。HTH Thomas