views:

90

answers:

3

Hi,

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

  1. Headlines
  2. Spot news (sub-headlines
  3. Spots with pictures
  4. Most read news (as titles)
  5. Most commented news (as titles)
  6. 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.

+2  A: 

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.

Tony k
+1  A: 

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.

SirDemon
+2  A: 

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.

Cyril Gupta
+1 for using Firebug and YSlow for client-side profiling.
Tony k