Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
507 views
in Technique[技术] by (71.8m points)

asp.net - call aspx page to return an image randomly slow

OK, here is the question, I have a asp.net website, there is an aspx page called GetThumbnail.aspx, the code is like below:

string newThumbnailPath = ReaderUtilities.GetThumbnailPath(ptiId, highQuality ? ZoomLevel.L : ZoomLevel.S);
Response.Clear();
if (File.Exists(newThumbnailPath))
{
  Response.ContentType = "image/jpg";
  Response.TransmitFile(newThumbnailPath);
}

That is it. the new newThumbnailPath is a network share path, usually like D:ImagesCache00001001230012345600123456-sml-1.jpg

Then in my website there is a searchResult.aspx, when user type some keyword to search, I will display the searchresult.aspx page, inside the searchResult.aspx, I will display 10 images, the code is below:

<img rel="429746" src="/GetThumbnail.aspx?p=429746" class="cover-img draggable">

OK, the question is, everytime, on production server, there must be several images loading very slow, say 8 images load within averagely 1 second, but 2 images take 7 or 9 seconds to load. All the images are small, and they don't need to resize, I used firebug Net to check, the slow loading images' DNS lookup, Connecting and Sending are all almost 1ms, and Receiving is 200 or 300ms, but the Waiting takes 8 or 9 seconds.

I thought it is because of IO, but why most of images are quick, just some and randomly, any help. I really appreciate it.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Because you use .aspx page (and not handler), and because the images loaded by browser not one by one, but many together, I suspect that you felt on the session lock of the page and that's why this delay.

Try to set EnableSessionState="false" on the page.

eg:

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" 
    AutoEventWireup="false" Inherits="WebApplication1.WebForm1" 
     EnableSessionState="false" %>

By the way, if you change the aspx page to a handler page you going to gain some more speed because the handler page did not make all the calls that a normally page do.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...