Investigating performance

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
1/19/2008 7:48:44 PM
Gravatar
Total Posts 3

Investigating performance

The site I am building runs slower than desired. Page load times are unacceptable.  What are a few places you would recommend a beginner to investigate when trying to improve performance?  I appreciate being pointed in the right direction.  Thank you.

1/20/2008 5:37:55 AM
Gravatar
Total Posts 18439

Re: Investigating performance

Hi Sean,

Are you asking for general advice in ASP.NET development of your own code or are you saying you are having performance problems with mojoPortal?

If using mojoPortal are you also using your own custom features?

Are you perceiving the slowness on a dev machine or a production machine. If your site is hosted on a shared hosting environment with a lot of other sites it could be starved for resources and its performance can be affected by other sites running on the machine.

In oder to optimize performance you have to be able to measure it, I use the MS ACT (Application Center Test) load tester that shipped with VS 2003 Enterprise Architect version. I mean if the page is loading extremely slow and you percieve there must be a problem in the code, it is possible to resolve it without load testing but once you get to the point where it runs reasonably well and you are just trying to increase performance you really need a load tester so you can measure before and after each change and make sure requests per second on the same test are going up not down as a result of the change.

To find slow running code that is a candidate for optimization I use RedGate Ants profiler. It can show you how often various sections of code are executed as well as how long they take so it helps in tracking down place where you can optimize and get the most improvement for your effort.

There are a number of common development mistakes to avoid which can cause drastic performance problems.

1. Too many database hits in serving a request. The more features on a page the more likely its making more db hits. Make approriate use of caching and don't look things up uneccesarily. If you do get data from the db and you will need it again during the request put the data in the HttpContext, don't retrieve it over and over every time you need it. Like in mojoportal we need access to the user data in many features and controls but during a request we only look it up once from the db. So the first use of the user data puts it in the HttpContext.Items collection and then any subsequent uses get it from there so we don't hit the db again for the same data in serving the request.

2. Retrieving more data than needed. Don't populate grids with hundreds or thousands of rows. Users can only digest a page at a time and its much more efficient if you retrieve just the needed page of data. Don't be tempted to brign back all the data in a DataSet then use the grid to page through it.


3. Forgetting to close DataReaders or connections after use. Very common mistake that can kill performance.

4. Don't make additional data lookups in the databinding events of a grid, I see this fairly often. The data for the grid needs some extra value not in the main data so on the databind event code loooks it up. So for every row in the grid it makes another db hit. Avoid this type of thing and fix the underlying data to bring back everything you need all  at once.


3. Use of large graphic files - I've seen people upload images right out of the camera and put them on the page, they see its too big so they set a width and height that makes it look smaller but the images is still a 1MB (or more) payload which makes the page slow. In general be aware of the total payload size of a page with all its images and html. Kepp it small as possibole for best performance.

4. When building for production deployment make sure you Rebuild in Release mode and don't deploy it built in debug mode. Also make sure in Web.config <compilation debug="false"....  if its true it loads debug symbols and makes it slower.

I'm sure there are more but those are the ones that pop into my head immediately.

Hope it helps,

Joe

 

1/20/2008 5:18:57 PM
Gravatar
Total Posts 3

Re: Investigating performance

Thank you very much, Joe.

I had been thinking of performance in terms of mojoportal, but I think you're right to direct me to general ASP.NET performance issues.  I'm basically running a fairly vanilla toolset, without any specialized code or odd 3rd party modules.  The site is on a shared hosting environment, but I would have normally expected it to run fine for 4 or 5 people using the site during development.  I will keep an eye on that issue, but would regret using ASP.NET if a dedicated machine were needed to host a low-to-moderate traffic site.

I appreciate the pointer on measuring and diagnostics.  You suggestions on where to begin are most welcome.  I will make good use of both tools.  Also, I'll see what I can do to optimize database hits as I clearly understand exactly what you're saying.  The details on where to start are tremendously helpful.  The images should not be a great impact as, while there are some, they have been compressed well during output.  And, turning off debugging is probably a useful reminder for this beginner. ;]

I know it's a bit of a shot in the dark to bring my attention to aspects I can investigate, so I thank you very much for the effort.  I will drill down through these threads until I've identified problem areas or have more specific questions.  Thanks again!

1/20/2008 6:28:08 PM
Gravatar
Total Posts 18439

Re: Investigating performance

One thing to keep in mind is not all shared hosting is equivalent. Some pack way too many sites on a machine or throttle your resources so low it barely works. You pretty much get what you pay for and the cheaper it is the less performance you'll get usually.

This site is running on shared hosting at DiscountASP.NET and performs fairly well most of the time but now and then it seems slow. One of the challenges with shared hosting is its hard to know if the perfomance issues are being caused by other sites on the server or your own. Also its hard to differentiate when I'm seeing slow performance if its my isp getting slow at times or the site.

I have a VPS that I'm considering moving this site to but since its already paid up for a good while I've been holding off on the move until it gets closer to renewal time.

Cheers,

Joe

1/20/2008 6:44:38 PM
Gravatar
Total Posts 18439

Re: Investigating performance

One more thing, if you're fairly new to ASP.NET you may not know about the compilation model. Although mojoPortal for instance is pre-compiled into dlls in the bin folder, those dlls are MSIL (Microsoft Intermediate Language) which is then further compiled to native code by the JIT (Just In Time Compiler). The JIT compilation takes place as needed by request so when the application starts and gets its first request its rather slow because of the JIT compilation that must happen before serving the request. The JIT compiled code is cached so performance increases on subsequent requests. The problem with this for sites that don't get much traffic is that the little trafic they do get is mostly first requests which are slow so the perception becomes that the site is slow. If the application gets no requests for 20 minutes it shuts down and then must be do the JIT again when it wakes up due to a new request.

As mentioned the code is JIT compiled as needed so say the first requst is for the home page and it has the html module. Well that module is in the mojoPortal.Web.dll, but next if I visit a page with an external feature with its own dll then a little more JIT happens when that dll is needed and so on. A high traffic site keeps mos things around because the app doesn't time out due to lack of requests.

ASP.NET apps can also be forcefully recycled by making a change in Web.config or by recycling the app pool in IIS. This of course causes the whole JIT cycle to start again.

So for slow traffic sites its like you need a little service at your house to ping the site every 15 minutes or so to keep the app alive so that when you get your few visitors its all fresh and doesn't need JITing. Otherwise the few visitors you do get will say its slow.

Anyway you may already know that stuff but fgured its worth a mention in case.

Cheers,

Joe

1/20/2008 6:58:16 PM
Gravatar
Total Posts 148

Re: Investigating performance

Hi Joe,

You said, "If the application gets no requests for 20 minutes it shuts down".  I don't think that is true by default.  If you are thinking of <processModel idleTimeout>, it defaults to Infinite.  You might also have been thinking of session timeout, which I think does default to 20, but just causes the session to be invalid, not an app recycle.

--Dean

 

1/20/2008 7:19:19 PM
Gravatar
Total Posts 18439

Re: Investigating performance

You are right about the default value for processModelIdleTimeout Dean but the gist of what I said is still true.

Its actually the IIS Application Pool timeout which defaults to 20 minutes and when no request is made it shuts down the worker process.

Joe

1/20/2008 7:49:12 PM
Gravatar
Total Posts 148

Re: Investigating performance

OK.  I see it now.  I'd never run into that before because I don't generally use IIS.

 

--Dean

 

1/20/2008 11:51:50 PM
Gravatar
Total Posts 3

Re: Investigating performance

This site is running on shared hosting at DiscountASP.NET and performs fairly well most of the time but now and then it seems slow.

I'm also hosting the site at DiscountASP.NET.

You must sign in to post in the forums. This thread is closed to new posts.