简体   繁体   中英

Azure Blob Storage Slow Using FileStreamResult Controller.File

I have an ASP.NET web site running on Azure Web Apps account. I also have a storage account using block blob mode.

I upload a video file that is only about 9 mb. It takes about 10 seconds to upload.

I then show a list of files to the user with a download link. When you click on the download link and "save as" the file it downloads. It takes > 30 seconds to download this same file.

This is extremely slow. It is only 9 mb and I have super fast internet. I can download most files from normal sites at > 3MB (mega byte) per second, so I would expect a 9 mb file to take about 3 seconds.

Here is the code I am using to return the stream via my controller:

    public Stream GetAttachmentStream(string attachmentId)
    {
        MemoryStream stream = new MemoryStream();
        var storage = Storage.Instance("StorageConnectionStringLive");
        storage.GetBlob(attachmentId, stream);

        stream.Seek(0, SeekOrigin.Begin);

        return stream;
    }

    public ActionResult GetFile(string id, string fileName, string mimeType)
    {
        var fileStream = GetAttachmentStream(id);

        Response.AppendHeader("Content-Disposition", "inline; filename=" + fileName);
        return File(fileStream, mimeType);
    }

Not really an answer to your question but some things you could do to identify where the problem is.

As I understand it, there're two things involved here: downloading blob from blob storage to your web server and downloading file from your web server to your browser. I believe that first we need to isolate where the problem of slowness is.

To see if there's an issue with downloading blob from blob storage to your web server, you can either put a timer in your GetAttachmentStream method or you can make use of OperationContext class in Azure Storage library. This class has StartTime and EndTime members which can tell you how much time the request has taken.

You can do the same thing for the code which sends the content to your web server. On the web server front, there could be many things which could also impact the download speed of blob.

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