简体   繁体   中英

Performance issue in a web site

We have hosted out site to amazon. And out of them one of the site is used to serve image dynamically. Where lots of operations done, creation of memory stream and all...

The system is behaving very odd.. It is working fine for some time, and then getting off for some time..and so on.

There is no perticular set of image url, for which it might behave badly. It is coming very random.

I have attached a Performance monitor, which I tracked to see what could be the issue, and my guess is, it could be due to some unmanaged memory issue. Four filters are :

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;
        }

Most of the errors that came for this mehtod are :

Unable to read data from the transport connection: A blocking operation was interrupted by a call to WSACancelBlockingCall.

The request was aborted: The request was canceled.

Stream does not support reading.

counter average minimum maximum in perfmon last

The operation has timed out.

Please give me some insight of what could be going wrong, or how can we track this?

There are two things you should look at:

  1. The code has a problem: The getObjectResponse.Dispose(); line will not get called when an error occurs, leading to memory leaks. Use a using statement or a finally block (which is the same in IL anyway).
  2. Also, the server's load (ie the number of simultaneous requests) might eventually be too high at some points. Check this (AWS provides the capabilities for that) and eventually switch to a bigger EC2 instance as needed.

HTH Thomas

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM