网站中的性能问题

时间:2013-12-07 12:28:19

标签: asp.net .net performance amazon-web-services amazon-ec2

我们已将网站托管到亚马逊。其中一个网站用于动态提供图像。完成大量操作,创建内存流和所有...

系统表现得很奇怪..它工作正常一段时间,然后下车一段时间......等等。

没有特定的图片网址集,因为它可能表现不佳。它随机而来。

我附加了一个性能监视器,我跟踪它以查看可能存在的问题,我的猜测是,可能是由于某些非托管内存问题。 四个过滤器是:

Process\Private Bytes
.NET CLR Memory# Bytes in all Heaps
Process\Working Set
.NET CLR Memory\Large Object Heap size

Performace Image

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的平均最小值

         

操作已经超时。

  

请告诉我一些可能出错的问题,或者我们如何跟踪这个?

1 个答案:

答案 0 :(得分:2)

您应该注意两件事:

  1. 代码有问题:发生错误时不会调用getObjectResponse.Dispose();行,导致内存泄漏。使用using语句或finally块(无论如何都与IL相同)。
  2. 此外,服务器的负载(即同时请求的数量)最终可能在某些点上过高。检查一下(AWS提供了相应的功能),并最终根据需要切换到更大的EC2实例。
  3. HTH Thomas