ASP.NET - my site is slow - Asked By Reena Jain on 29-Jan-10 02:32 AM

Hi,

I am using asp.net 2008 with sql server 2008, and for ajax i am using telerik redcontrol, but my site is working very slow even there are few forms in it means only 10 forms. Even on local its working slow when i run it locally and open any form at run time and go in sloution explorer then at run in solution explorer it shows a lot of text file with the name of anonymous code and eval code.

thanks
Huggy Bear replied to Reena Jain on 29-Jan-10 02:41 AM
Slowness of the application is not because of the number of forms you have, it depends on

1. The number of server control you have on the form.
2. The volumn of data you display on the form.
3. The volume of data that you store in the ViewState, which ends up sitting on your web page.
4. The geographic location of your web server and the client machine.
5. Also the number of records retrieved from the database.
6. Number of connections made to your database from your page's code behind.

Check for the above mentioned scenarios in you application and perform the optimization accordingly.
mv ark replied to Reena Jain on 29-Jan-10 02:46 AM

Try finding where the bottleneck lies.  

For analyzing your back-end performance, run Sql Profiler while you are running your application

To analyze code inefficiencies, use Visual Studio 2008 Code Profiler or ANTS Profiler -
http://blog.maartenballiauw.be/post/2008/02/Code-performance-analysis-in-Visual-Studio-2008.aspx
http://www.red-gate.com/products/ants_profiler/index.htm

On the browser use tools like YSlow (http://developer.yahoo.com/yslow/) alongwith Firebug (http://www.getfirebug.com/) on Firefox to analyze front-end performance.

Read the 36 Best Practices for Speeding Up Your Web Site from the Yahoo Exceptional Performance team - http://developer.yahoo.com/performance/rules.html

One of the best resources for tips on improving Performance and Scalability is the MS Pattern and Practices guide - "Improving .NET Application Performance and Scalability"
You can download it from this link : http://www.microsoft.com/downloads/details.aspx?FamilyId=8A2E454D-F30E-4E72-B531-75384A0F1C47&displaylang=en or read it online here - http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/scalenet.asp

The guide is very exhaustive and checklists at the end consolidate the key points

Santhosh N replied to Reena Jain on 29-Jan-10 03:08 AM
And to add a point here on your last concern about the anonymous code, thats nothing to do with the application performance and those are the files that are consumed and shown in the solution explorer where there are useful to debug the js and css files...
Kalit Sikka replied to Reena Jain on 29-Jan-10 03:33 AM

List of point that could help in Optimizing the Code


1. Disable ViewState - Set "EnableViewState=false" for any control that does not need the view state. As a general rule if your page does not use postback, then it is usually safe to disable viewstate for the complete page itself.

2. Use Page.Ispostback is used in Page_Load - Make sure that all code in page_load is within "if( Page.Ispostback)" unless it specifically needs to be executed upon every Page Load.
Asynchronous calls for Web Services - If you are using Web Services in you page and they take long time to load, then preferably use Asynchronous calls to Web Services where ever applicable and make sure to wait for end of the calls before the page is fully loaded. But remember Asynchronous calls have their own overheads, so do not overdo it unless needed.

3. Use String Builder for large string operations - For any long string operations, use String Builder

instead.

4. Specialized Exception Handling - DO not throw exceptions unless needed, since throwing an exception will give you a performance hit. Instead try managing them by using code like "if not system.dbnull …." Even you if you have to handle an exception then de-allocate any memory extensive object within "finally" block. Do not depend on Garbage Collector to do the job for you.
//
// Try
// 'Create Db Connection and call a query
// sqlConn = New SqlClient.SqlConnection(STR_CONN)
// Catch ex As Exception
// 'Throw any Error that occurred
// Throw ex
// Finally
// 'Free Database connection objects
// sqlConn = Nothing
//End Try
//

6. Leave Page Buffering on - Leave Page buffering On, unless specifically required so. Places where you might require to turn it on in case of very large pages so that user can view something while the complete page is loading.
Use Caching - Cache Data whenever possible especially data which you are sure won't change at all or will be reused multiple times in the application. Make sure to have consistent cache keys to avoid any bugs. For simple pages which do not change regularly you can also go for page

 

Caching
//
// <% @OutputCache Duration="60" VaryByParam="none" %>
//

Learn more about "VaryByParam" and "VaryByControl" for best results.
Use Script files - As a rule unless required do not insert JavaScript directly into any page, instead save them as script file ".js" and embed them. The benefit being that common code can be shared and also once a script file is loaded into browser cache, it is directly picked up from browser cache instead of downloading again.
Remove Unused Javascript - Run through all Javascript and make sure that all unused script is removed.
Remove Hidden HTML when using Tabstrip - In you are using a Tabstrip control and if the HTML size is too large and the page does frequent reloads, then turn Autopostback of Tabstrip on, put each Pageview inside a panel and turn visibility of all Panels except the current one to False. This will force the page to reload every time a tab is changed however the reload time will reduce heavily. Use your own jurisdiction to best use.
Additional Checklist for performance critical pages

Disable session when not using it - If your page does not use session then disable session specifically for that page.
//
// <%@ Page EnableSessionState="false" %>
//

If the page only reads session but does not write anything in session, then make it read only.
//
// '<%@ Page EnableSessionState="ReadOnly" %>
//

7. Use Option Strict On (VB .Net only) - Enabling Option Script restricts implicit type conversions, which helps avoid those annoying type conversion and also is a Performance helper by eliminating hidden type conversions. I agree it takes away some of you freedom, but believe me the advantages outweigh the freedom.

8. Use Threading - When downloading huge amounts of data use Threading to load Data in background. Be aware, however, that threading does carry overhead and must be used carefully. A thread with a short lifetime is inherently inefficient, and context switching takes a significant amount of execution time. You should use the minimum number of long-term threads, and switch between them as rarely as you can.

9. Use Chunky Functions - A chunky call is a function call that performs several tasks. you should try to design your application so that it doesn't rely on small, frequent calls that carry so much overhead.

10. Use Jagged Arrays - In case you are doing heavy use of Multi Dimensional Arrays, use Jagged Array ("Arrays of Arrays") Instead

11.Use "&" instead of "+" - You should use the concatenation operator (&) instead of the plus operator (+) to concatenate strings. They are equivalent only if both operands are of type String. When this is not the case, the + operator becomes late bound and must perform type checking and conversions.

12. Use Ajax - In performance critical application where there are frequent page loads, resort to Ajax.

13. Use the SqlDataReader class - The SqlDataReader class provides a means to read forward-only data stream retrieved from a SQL Serverâ„¢ database. If you only need to read data then SqlDataReader class offers higher performance than the DataSet class because SqlDataReader uses the Tabular Data Stream protocol to read data directly from a database connection
Choose appropriate Session State provider - In-process session state is the fastest solution. If you store only small data in session state, go for in-process provider. The out-of-process solutions is useful if you scale your application across multiple processors or multiple computers.

14. Use Stored Procedures - Stored procedures are pre-compiled and hence are much faster than a direct SQL statement call.

15. Use Web Services with care - Web Services depending on data volume can have monstrous memory requirements. Do not go for Web Services unless your Business Models demands it.
16. Paging in Database Side - When you needs to display large amount of Data to the user, go for a stored procedure based Data Paging technique instead of relying on the Data Grid/ Data List Paging functionality. Basically download only data for the current page.

 

 

 

Web Star replied to Reena Jain on 29-Jan-10 03:37 AM

The performance is not cause of one thing, u need to take care of these important thing for boost up your site

1.First of make sure u put only requred thing on page , remove all unused control

2.if possible then get only required data from database

3. don't use unnessary session or cache object

4. if not nessary then avoid server side validation code

5.use stored proc with optimized way and also take proper indexing in database for fast access record when needed

6 always fetch only desired field from database table

7. disable ViewState if not required.

and also need lots of point in mind related to performance

Victor Chernov replied to Reena Jain on 15-Feb-10 09:40 AM

Try FastSQLDataSource. It helps when you need faster display of large amounts of data in your web application using grids, lists and other bound controls.

http://www.nitrosbase.net

It can work almost without coding or sometimes with no coding at all.