Go Back   DeveloperBarn Forums > Programming & Scripting > .Net Development

Sponsored Links

Discuss "Slow Page Processing" in the .Net Development forum.

.Net Development - Learn about the Microsoft.Net framework and how to create powerful web-based (ASP.net) and client-based (Windows Forms) applications utilizing various languages such as C#, VB.Net, J# and others.


Reply « Previous Thread | Next Thread »
 
LinkBack Thread Tools Display Modes
  #1  
Old August 5th, 2008, 08:23 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default Slow Page Processing

I have now launched our .NET App, but we seem to be having loads of speed issues. Some pages are taking an age to load and postback.

I've tried using System.Diagnostics.Stopwatch to measure the Page Load in both the master and content pages by starting it in the Page_Init event and stopping it at the end of Page Load but the times it's coming back with don't seem to match the amount of time the page is taking to load.

Everything just seems to be very slow.

Any ideas on what might be causing it?

At this rate we're going to have to go back to Classic ASP.

Thanks
Reply With Quote
Sponsored Links
  #2  
Old August 5th, 2008, 08:28 AM
jmurrayhead's Avatar
The Barnfather

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 820
Thanks: 20
Thanked 74 Times in 71 Posts
Blog Entries: 5
Rep Power: 3
jmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura about

Awards Showcase
Microsoft .Net Microsoft SQL Server Microsoft Windows Classic ASP 
Total Awards: 4

Default

Without seeing the app in action and the methods you have developed, it's hard to tell.

Have you measured the time it takes for your individual queries?

Are you sure you're closing all connections when you need to with in the Try..Catch...Finally blocks?

Have you implemented any caching on data that does change often?

Have you verified it's not a network problem?
__________________
jmurrayhead
If you agree with me... click the icon!
If my post solved your problem, click the button in the lower right-hand corner of the post.

Join our Folding team: DeveloperBarn Folding
Reply With Quote
  #3  
Old August 5th, 2008, 08:52 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

Quote:
Originally Posted by jmurrayhead View Post
Without seeing the app in action and the methods you have developed, it's hard to tell.
I know. It's running on a shared host and I read somewhere that .NET 2.0 requires a lot of resource to run. Surely a shared host should be good enough to run it efficiently?

Quote:
Originally Posted by jmurrayhead
Have you measured the time it takes for your individual queries?
I've run quite a few of the queries in a query analyser and they only seem to take up to about a second to run (for the biggest). Wouldn't the stopwatch diagnostic take this into account though? If you call a sub from your Page_Load event (for example, to populate a datalist), that sub runs all the way to the end before it returns to the Page_Load, doesn't it?

Quote:
Originally Posted by jmurrayhead
Are you sure you're closing all connections when you need to with in the Try..Catch...Finally blocks?
I think so...I'm fairly certain I always include a Finally block that disposes of the Command and Connection objects.
Quote:
Originally Posted by jmurrayhead
Have you implemented any caching on data that does change often?
Should that be does or doesn't change often? I don't cache any data at the moment. There are possibly a few things we could cache, but nothing major and I wouldn't know how to do this. Could you show me an example?
Quote:
Originally Posted by jmurrayhead
Have you verified it's not a network problem?
All other websites seem to load pretty fast on the internet connection they have. I've asked my host if there is anything they can see that might cause it to be slow.
Reply With Quote
  #4  
Old August 5th, 2008, 09:05 AM
jmurrayhead's Avatar
The Barnfather

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 820
Thanks: 20
Thanked 74 Times in 71 Posts
Blog Entries: 5
Rep Power: 3
jmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura about

Awards Showcase
Microsoft .Net Microsoft SQL Server Microsoft Windows Classic ASP 
Total Awards: 4

Default

Quote:
Originally Posted by richyrich View Post
I know. It's running on a shared host and I read somewhere that .NET 2.0 requires a lot of resource to run. Surely a shared host should be good enough to run it efficiently?
It depends on the host and their hardware...but typically it should be fine.


Quote:
Originally Posted by richyrich View Post
I've run quite a few of the queries in a query analyser and they only seem to take up to about a second to run (for the biggest). Wouldn't the stopwatch diagnostic take this into account though? If you call a sub from your Page_Load event (for example, to populate a datalist), that sub runs all the way to the end before it returns to the Page_Load, doesn't it?
Just wanted to be sure about the queries...if they are fast in query analyzer then the query isn't the problem. Yes, the sub would run completely until exited and then The Page_Load will complete.


Quote:
Originally Posted by richyrich View Post
I think so...I'm fairly certain I always include a Finally block that disposes of the Command and Connection objects.
Should that be does or doesn't change often? I don't cache any data at the moment. There are possibly a few things we could cache, but nothing major and I wouldn't know how to do this. Could you show me an example?
What I'm referring to is data that DOES NOT change often. There is no sense in requerying a database if the data doesn't change much. If you use ObjectDataSource to populate GridViews and such, you can use its caching properties. Check out the MSDN for more information on that. You can also cache your business objects. See post #5 here for a good example (C# but you can convert it if you don't understand it): Caching business objects? - .NET ASP
Reply With Quote
  #5  
Old August 5th, 2008, 09:35 AM
Wolffy's Avatar
Slaprentice of Wolves

 
Join Date: Mar 2008
Location: Peoria, IL
Posts: 175
Thanks: 3
Thanked 24 Times in 21 Posts
Rep Power: 1
Wolffy is on a distinguished road

Awards Showcase
Microsoft .Net 
Total Awards: 1

Default

You might want to try turning Tracing on -- it could give you a idea where most of the time is being spent in processing you page. (or not).
__________________
Wolffy
------------------------
Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Rework for your specific environment may be required. Void where prohibited by law. Not valid in California. Your mileage may vary.
Reply With Quote
  #6  
Old August 5th, 2008, 09:45 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

Quote:
Originally Posted by Wolffy View Post
You might want to try turning Tracing on -- it could give you a idea where most of the time is being spent in processing you page. (or not).
Thanks Wolffy. Could you give me some idea of what I do to use it and how it works?
Reply With Quote
  #7  
Old August 5th, 2008, 09:51 AM
Wolffy's Avatar
Slaprentice of Wolves

 
Join Date: Mar 2008
Location: Peoria, IL
Posts: 175
Thanks: 3
Thanked 24 Times in 21 Posts
Rep Power: 1
Wolffy is on a distinguished road

Awards Showcase
Microsoft .Net 
Total Awards: 1

Default

Sure. Take a look at ASP.NET Tutorials: Tracing in ASP.NET 2.0 for a pretty good article on the subject.
Reply With Quote
The Following User Says Thank You to Wolffy For This Useful Post:
richyrich (August 5th, 2008)
  #8  
Old August 5th, 2008, 10:37 AM
jmurrayhead's Avatar
The Barnfather

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 820
Thanks: 20
Thanked 74 Times in 71 Posts
Blog Entries: 5
Rep Power: 3
jmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura about

Awards Showcase
Microsoft .Net Microsoft SQL Server Microsoft Windows Classic ASP 
Total Awards: 4

Default

Instead of using Try Catch Finally and calling conn.close in the Finally block...you could use Using. Calling conn.close() allows the .Net garbage collector to handle the connection closing. With Using...it is closed immediately. Here's an example:

Code:
Dim cn As SqlConnection = New SqlConnection(_connectionString)
Dim cmd As SqlCommand = New SqlCommand("usp_GetAllRecords", cn)
 
Using cn
    cn.Open()
    Dim dr As SqlDataReader = cmd.ExecuteReader
    While dr.Read
        ' Do something with the data
    End While
End Using
Also, I wanted to mention that you should ensure you're only calling your data retrieval methods when you need them. If you're always calling something in Page_Load, even though you don't need that data, you can see a significant decrease in performance.
Reply With Quote
  #9  
Old August 5th, 2008, 10:59 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

Quote:
Originally Posted by jmurrayhead View Post
Instead of using Try Catch Finally and calling conn.close in the Finally block...you could use Using. Calling conn.close() allows the .Net garbage collector to handle the connection closing. With Using...it is closed immediately. Here's an example:

Code:
Dim cn As SqlConnection = New SqlConnection(_connectionString)
Dim cmd As SqlCommand = New SqlCommand("usp_GetAllRecords", cn)
 
Using cn
    cn.Open()
    Dim dr As SqlDataReader = cmd.ExecuteReader
    While dr.Read
        ' Do something with the data
    End While
End Using
Also, I wanted to mention that you should ensure you're only calling your data retrieval methods when you need them. If you're always calling something in Page_Load, even though you don't need that data, you can see a significant decrease in performance.
Thanks for that J....How would you deal if an exception is thrown inside a Using...? I use catch to write a message back to the user telling them there was a problem. How would you do this with Using?

On your last point, within my Page_Load I use various subs to build dropdownlists and datalists on a page. I don't build anything I don't need.

But, for example, on one page I have a dropdown for category, clients, introducers, users so I built a seperate sub for each dropdown/datalist to query the db and bind the data to the relevant dropdown/datalist (this was before I understand the whole layers structure). Would it be more efficient to use a List(Of ) class in each BOL to build these lists?

The reason I ask is that I have a page that shows a list of current clients using a repeater. I tried 3 different methods of building the list, constructing the sql in the page and binding it, constructing it in the dal and building a List Of and using a Stored Proc to build the List Of. I found constructing the query in the Page and binding it to be the quickest method.

Which method would you use for constructing dropdowns and the like?
Reply With Quote
  #10  
Old August 5th, 2008, 11:11 AM
Wolffy's Avatar
Slaprentice of Wolves

 
Join Date: Mar 2008
Location: Peoria, IL
Posts: 175
Thanks: 3
Thanked 24 Times in 21 Posts
Rep Power: 1
Wolffy is on a distinguished road

Awards Showcase
Microsoft .Net 
Total Awards: 1

Default

The beauty of Using is that no matter how you drop out of it, the connection is always closed.
Reply With Quote
Reply

  DeveloperBarn Forums > Programming & Scripting > .Net Development

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Open Web Page Jaykappy Microsoft Access 2 May 14th, 2008 06:32 PM
Slow Concat Code AOG123 Microsoft Access 30 May 8th, 2008 02:10 PM
go page to page questionaire app peebman2000 .Net Development 3 April 26th, 2008 04:42 PM
page transfer todd2006 JavaScript Programming 2 April 7th, 2008 02:26 PM
Alpha Page Numbers AOG123 Microsoft Access 4 March 19th, 2008 11:24 AM


All times are GMT -4. The time now is 08:32 PM.



Content Relevant URLs by vBSEO 3.2.0