I am puzzled. I looked at the trace of a pagecall that was "slow" to load according to my boss, causing the page to partially load, and then "jump" to the memorized scroll-place on a postback.
I found out eventually, using my trace, that my whole loading, from Begin PreInit to End Render, took 1.94 seconds, 1.5 of which are spent between Begin PreRender and End PreRender.
Any idea on what could cause that? The next biggest loadtime is 0.14 seconds, for End PreRenderComplete.
Could the problem originate from my queries to SQL Server, or a too vast quantity of controls on the page, even though most are "hidden"?
[edit:]It seems that my page load is very long when I show a certain form. My total render size is of 91537 bytes, 44483 of which are dedicated to that specific form. My viewstate seems kindof enormous. Also: Can a 404 to a JS file cause that kind of lag on load?
[update:] So I found the longest-running query, and it seems that even though it DOES seem quite chunky, it has ended running long before the page is even loaded.
As added information: I am using quite a bit of SqlDataSources troughout the controls, to fill my dropdownlists and other interesting stuff of the like. Is that cluttering my app?
In my experience (same problem as you), it's 90% a SQL issue.
Put some Stopwatch(es) around the query you are calling to find out which query is running slow.
Rendering asp.net control can't take so long....
In order to identify the cause of a bottleneck you really ought to profile your code with a tool like ANTS Profiler or something similar.
A profiler will allow you to pinpoint the problem area by showing you which lines of code are slower than others.
I would use YSlow to determine if its from something on the client side or server side. We sometimes add timers to some queries then output the time to execute in an html comment... of course removing them when the testing is complete.
Does the page call anything hosted on an external site?
Your best bet is to use the Perfomance Wizard in Visual Studio and look at the Call Tree for your page. It will give you more details into the exact performance bottleneck.
I have seen this type of performance when there are too many complex controls declared on the page. Although it could easily be SQL related as well. To know for certain you need to look at the Call Tree and find out what the most expensive call is.
Of course, if it is sql-related, as many people have noted, "sql server profiler" is the tool to use (given that you're running mssql). mysql has "jetprofiler" (.com) which i haven't tried. once you've found the slow query, it's not rarely an indexing issue.
Related
Is it possible, within an asp.net page, to the get time at which point that page was last compiled?
I would like to distinguish between when a page has been delivered, and when that page has been updated, compiled, and then delivered (typically there's a slight delay, but a compile timestamp would make things a bit more concrete).
Ideally a simple solution exists, it's not particularly critical but a bit frustrating when during development we end up refreshing a page x times before the recompiled version appears.
cheers :)
As suggested in the comments, it's likely that this is not possible. I want to close the question but also feel it's useful in case someone searches for similar to know it's already been asked.
I think
beestings change the html every time.
this means html is not able to be cached.
am I right?
I assume that by beesting, you mean some sort of random number in the URL.
Yes this will (usually) stop caching of pages. Some browser may still cache some or all of the page.
As to whether not to avoid it. Would caching a page stop it working as it should? If your page has fairly random content or content the changes often, users would not see this if the page is cached.
If you can avoid the need to stop caching, pages will be able to load faster. Which makes for a happy user.
Old, old question, but anyway... no. You actually can "cache some or all of the response generated by an ASP.NET page, referred to in ASP.NET as output caching". You can read more at this Microsoft page.
For those still wandering, bee stings are special tags used in Microsoft's asp.NET to hold server-side code, much like PHP would do. It is, or was, very common to keep simple code inline, although having significant amount of code in bee stings is considered a bad practice by Microsoft themselves.
But as a rule, yeah, it can be cached.
I am new to asp.net and have got some concerns about the bloated viewstate on a small site I'll be maintaining.
Since I actually don't want to learn asp.net (mvc looks interesting though), my question is if I should care about this potential issue or just wait 4 years until its time to rewrite the site....
Hopefully some of you have some experience or already have done a proper research to help me decide if it's worth the time to do something about it.
I am not interested in workarounds since if this is a serious issue I have found info about different ways to reduce the viewstate. (Although it requires me to understand the framework and code.)
Thanks.
some search engines only process the first few KBs of the page if the page size is large. As viewstate is a hidden input at the top of the form/page this can impact SEO as the actual content of the page may not get fully processed by the search engine if there is too much viewstate. Look into moving the viewstate to the bottom of the page.
http://www.hanselman.com/blog/MovingViewStateToTheBottomOfThePage.aspx
It can cause excessive page weight but this will not hurt your standing with the search engines. ViewState is stored in a hidden input which are mainly ignored by search engines.
I know this thread is old but in ASP.Net every control including the page itself has a property called EnableViewState. All one has to do is turn it to false if they do not need a control to maintain state or for that matter the page itself
I have developed a site using Asp.net C# 3.5 and now I feel that some of the pages are loading reeeaaally slooooow. I now need to start going through the website and try to find out whats making it so slow. But I don't know where to start, whats most likely causing the problem? Where do you usually start when trying to find out what is wrong?
One page that is very slow uses the following:
Asp.net C# 3.5
AjaxControlToolkit (http://www.asp.net/ajax/AjaxControlToolkit/Samples/)
RoundedCornersExtender
CollapsiblePanelExtender
Two different UpdatePanels
11 connections to a MySql database (one quite heavy, using some unions and inner joins)
Most of the connections to the database results in populating FormViews or GridViews, so totally I have 2 formviews and 6 gridviews on the page (every gridview show max 10 items)
Can a CSS-file slow down the site? The CSS file I use is about 60kb.
Can using the AjaxControlToolkit make the site slow? Is there a better way to use javascripts on the site?
I understand that it's impossible for you to help me locate the problem with slow load but where you would start to look for the problem? The DataControllers? The AjaxControlToolkit? The sql? Is it an easy way to find out if a query in mysql is slow? And what is slow? Is 0.3s slow for a large query?
As you see I have many questions, maybe you could just help me start working in the right direction, thanks really much for your help!
You could start adding Trace="True" into your <%# Page %> directive and see where your pages spent most time; also check your web.config and config debug is disabled.
You can also use Performance Monitor to help you to identify your application main bottlenecks
Don't forget about
ASP.NET Tracing
as probably the first, and simplest thing, to start diagnosing ASP.NET problems.
If you want to get a bit more in-depth, don't forget to try:
ASP.NET Health Monitoring
From what you say, though, personally, I'd look into possibly reducing those database connections. Data access is always a major bottleneck (or can be). 11 connections is quite a lot for a single page, especially if one or more of those connection does "heavy" work as you say. Could the page be split into two or more pages? If the problem is in the rendering of the page, the output from ASP.NET Tracing should help in this regard.
The CSS file, whilst quite large at 60kb, is possibly the least likely culprit as most browsers will cache the CSS file after the first request.
My general method when dealing with something like this is always the same. I start removing functionality - javascript/css/include files - until the page becomes more responsive - often i take the page back to minimum complexity and build from here. Adding them back one by one you should be able to identify where your bottleneck is. You can also use tools like (for MySQL) the slow query log to identify problematic queries. Abstracting your queries out and running them in phpmyadmin (or similar) can also help you recognise which queries are problems if this is the case.
I guess the first thing you need to identify is what exactly is "slow" about the page, is it rendering time? load time? identifying this should give you a good starting point.
First of all you will need to do some profiling/measuring to find out which part of the application is slow, e.g:
long running db queries
CPU/memory usage on the web/db server
amount of data transferred between web server and client (browser)
time it takes to render the pages in the browser (javascript)
I'd start with checking how long those SQL queries are taking to execute. Not sure what the SQL Profiler type tool for MySql would be called. If that is not the culprit you could create a TraceAttribute as shown here to see how long each of your methods take to execute. If that is not the culprit you could go onto using something like FireBug or Fiddler to see how long each part of your site takes to load and how long each request takes. You could also use Tracing instead of Post Sharp, but when you have a hammer every problem looks like a nail.
I built an online news portal before which is working fine for me but some say the home page is slow a little bit. When I think of it I see a reason why that is.
The home page of the site displays
Headlines
Spot news (sub-headlines
Spots with pictures
Most read news (as titles)
Most commented news (as titles)
5 news titles from each news category (11 in total e.g. sports, economy, local, health
etc..)
now, each of these are seperate queries to the db. I have tableadapters datasets and datatables (standard data acces scenarios) so for headlines, I call the business logic in my news class that returns the datatables by the tableadapter. from there on, I either use the datatable by just binding it to the controls or (most of the time) the object converts it to a list(of news) for example and I consume it from there.
Doing this for each of the above seems to work fine though. At least it does not put a huge load. But makes me wonder if there is a better way.
For example, the project I describe above is a highly dynamic web site, news are inserted as they arrive from agencies 24 hours non-stop. so caching in this case might not sound good. but on the other hand, I know have another similar project for a local newspaper. The site will only be updated once a day. In this case:
Can I only run one query, that would return a datatable containing all the news items inserted for today, then query that datatable and place headlines, spots and other items to their respective places on the site? Or is there a better alternative around? I just wander how other people carry out similar tasks in the most efficient way.
I think you should use FireBug to find out what elements are taking time to load. Sometimes large images can ruin the show (and the size of the image on screen isn't always relative its download size).
Secondly you could download the Yahoo Firefox plugin YSlow and investigate if you have any slowing scripts.
But Firebug should give you the best review. After loading Firebug click on the 'Net' tab to view the load time of each element in the page.
If you've got poor performance, your first step isn't to start mucking around. Profile your code. Find out exactly why it is slow. Is the slowdown in transmitting the page, rendering it, or actually dynamically generating the page? Is a single query taking too long?
Find out exactly where the bottleneck is and attack the problem at its heart.
Caching is also a very good idea, even in cases where content is updated fairly quickly. As long as your caching mechanism is intelligent, you'll still save a lot of generation time. In the case of a news portal or a blog as opposed to a forum, your likely to improve performance greatly with a caching system.
If you find that your delays come from the DB, check your tables, make sure they're properly indexed, clustered, or whatever else you need depending on the amount of data in the table. Also, if you're using dynamic queries, try stored procedures instead.
If you want to get several queries done in one database request, you can. Since initially you wont be showing any data until all the queries are done anyhow, and barring any other issues, you'll at least be saving time on accessing the DB again for every single query.
DataSets hold a collection of tables, they can be generated by several queries in the same request.
ASP.NET provides you with a pretty nice mechanism already for caching (HttpContext.Cache) that you can wrap around and make it easier for you to use. Since you can set a life span on your cached objects, you don't really have to worry about articles and title not being up to date.
If you're using WebForms for this website, disable ViewState for the controls that don't really need them just to make the page that little bit faster to load. Not to mention plenty of other tweaks and changes to make a page load faster (gzipping, minimizing scripts etc.)
Still, before doing any of that, do as Anthony suggested and profile your code. Find out what the true problem is.