views:

148

answers:

8

I was recently asked to speed up a C#/ASP.NET/SQL Server business app website. Since I just started, I don't know too much about the internals. So where do I start? Sight unseen, what is the single most important thing affecting performance on a system like this? Database tuning? Hardware? Individual page optimization? What is the first thing you'd look at?

EDIT: After I actually do the work, I'll come back and post the answer. ;)

EDIT again: "Profile" is currently the most-voted answer, and I agree that that is clearly what one should do. But I was looking for guesses/experience as to what the profiling results would show, so I don't think that answer counts...

+5  A: 

The first thing i would look at is the database, make sure there are indexes where indexes should be.

John Boker
A: 

I'd vote for database locking issues from my experience.

Chris
+9  A: 

What is the first thing you'd look at?

A profiler.

Daniel Pryden
Fair enough... profiling what? SQL queries, the code executing on the server, the client-side javascript, the requests.. ?
Scott Stafford
@Scott: Yes. Profile those things.
Hogan
I'd start with either RedGate ANTS or JetBrains dotTrace and just run it over all the C# code. Where the hotspots are in the database, you'll see it show up as calls into the System.Data layer. Where the hotspots are in C# code it will show you. It won't help with the client-side layer, but it will show you if the client side is making too many requests, or too frequently, which will at least point you in the right direction.
Daniel Pryden
+6  A: 

The first thing I'd do is get a copy of JetBrains' dotTrace application, and use it to profile the site. Don't make assumptions about where the performance problem lies - go find out!

John Saunders
How does dotTrace (haven't heard of it) compared to IBM Rational Quantify (which I've used extensively on C++ apps)?
Scott Stafford
@Scott: I've never used the IBM product, so I don't know.
John Saunders
+4  A: 

Anything could be the problem. Take a page that is behaving badly and trace the flow of control. Use the debugger and the sql profiler and see EVERYTHING that page does. It should be clear what to fix then.

Remember to start on a page users are frustrated with being slow. Don't bother with other pages (eg the login page, which almost never is an issue.)

Of course, with experience you could just look at the codes (DB + .NET) and know what the problem is, but you don't have the experience. Thus another option is to hire a consultant who has experience.

Edit - My guesses (cuz I want a cookie)

  • If it is AJAX it could be the JavaScript
  • Otherwise it is most likely the TSQL
  • Unless the programmer did not know how to use TSQL and just pulled in whole DB Tables and manipulated the data in C#
  • or the programmer had no understanding of the page model (or MVC model) and it is the most bizarre code you have ever seen in your life.

I've see all of these.

Hogan
I do back up Hogans proposal. The other great thing from here is that analysing why this specific page is working slowly, you will start to understand better both the internals of the app (at least the layers, which in theory should be the same for all pages, the database structure, or at least part of that, and the code style). This will help you to tune in other pages after that. I would definitely look at adding some instrumentation code if possibe in the page (knowing that in theory this could make it slower) and use SQL Profiler as a tool to understand the DB.
Wagner Silveira
@Wagner: Thanks -- yes this is by far the best plan for a beginner. You will learn lots doing this @Scott
Hogan
@downvoter: Always nice to get a down vote with no explanation.
Hogan
+1  A: 

Using a profiler is a good way to measure performance but tricky if you don't do a reasonable emulation of production performance.

Most DB-backed web applications are I/O-bound not compute-bound. Absent a profiler, I would guess query performance. You can improve query performance by running an explain query play to figure out what indexes you need. Or avoid having to optimize a query by putting result sets/active records into a cache.

Alan
+1  A: 

For the database part, here is a good start what to look for:

Troubleshooting Performance Problems in SQL Server 2005

But I wouldn't also be suprised if you find ineffective client code. Especially when communicating with the database.

Frank Kalis
A: 

It turns out that the most egregious problem was a few trouble pages that hammered the database with thousands of SQL queries. The code was relatively innocent-looking, just some data bound grids. However, C#/LINQ was a bit too powerful for its (or our) own good: if you bind a grid to a table, but the grid wants to display a field from another table linked via foreign key, it does it! But it does it by running a zillion queries:

SELECT ... FROM other_table WHERE Id = 1
...
SELECT ... FROM other_table WHERE Id = 2
...
SELECT ... FROM other_table WHERE Id = 3
...
SELECT ... FROM other_table WHERE Id = 4
...

and so on... by making sure that the dataset that was bound to the control had all necessary data without requerying the database, the problems eased noticeably.

Now back to profiling...

Scott Stafford