Reputation: 787
I have asked this question ever before and it seems I didn't 100% resolved it. Please see link A search aspx page return slow, I disable the IIS logs, but it seems still load slowly.
I have a asp.net website, there is a searchResult.aspx, it runs a sql script to retrieve data from MS SQL server database, and then put the data into a HTML format, the website has been deployed in IIS7.5 Server. I have implemented both static and dynamic compression, that means all my js, css and aspx page have been compressed before rendered to browser.
Unfortunately the searchResult.aspx return very slow, if search for a big word, like biography, it averagely takes more than 10 seconds to return. and I used firebug Net to trace it, the blocking, DNS Lookup, Connecting and Sending all take no more than 10ms, but the Waiting takes over 10 seconds. So I added some code to the beginning and end of function Page_Load(object sender, EventArgs e) and also the begining and end of HTML body element, like below:
protected Stopwatch stopwatch = new Stopwatch();
protected void Page_Load(object sender, EventArgs e)
{
stopwatch.Start();
....
stopwatch.Stop();
timeForSearch = stopwatch.Elapsed.Milliseconds;
}
<body>
<%
stopwatch.Reset();
stopwatch.Start();
%>
....
<%stopwatch.Stop();%>
<%=timeForSearch%>+<%=stopwatch.Elapsed.Milliseconds%>= <%=stopwatch.Elapsed.Milliseconds + timeForSearch%>
OK, you can see the pic, the highlight is the millinseconds elapsed, but why it took 4.8 seconds to load.
Any help will be appreciated.
Upvotes: 0
Views: 3993
Reputation: 787
Ok, I thought I found out the reason why the search page load slowly, just all of your concerns, it is because of SQL script, the reason why I didn't notice it is because the code error, I used the
stopwatch.Elapsed.Milliseconds
Actually I should use
stopwatch.ElapsedMilliseconds
The difference between them are in Difference between ElapsedTicks, ElapsedMilliseconds, Elapsed.Milliseconds and Elapsed.TotalMilliseconds? (C#). And it finally shows me that my Page_Load() method takes sometimes more than 5, or 7 seconds to load according to the search term.
So I will need to improve the sql script, cause it is very big, so I will not write down it. Anyway thanks all you guys, I was inspired by your concerns.
Upvotes: 1