asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search





Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Archive
Writers
Code Samples
Components
Tools
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

Tips to Improve ASP Application Performance
By Srinivasa Sivakumar
Rating: 3.7 out of 5
Rate this article


  • email this article to a colleague
  • suggest an article

    Introduction

    Performance tuning can be tricky. It's especially tough in Internet-related projects with lots of components running around, like HTML client, HTTP network, Web server, middle-tier components, database components, resource-management components, TCP/IP networks, and database servers. Performance tuning depends on a lot of parameters and sometimes, by changing a single parameter, performance can increase drastically.

    Performance Issues

    ASP application performance involves two parts:

    • HTML page performance
    • Response time

    Further, we can boil down response rime to:

    • ASP page performance
    • Network bandwidth
    • Database issues

    Let's see each of them in detail.

    HTML Page Performance

    HTML page performance is purely a client problem. This problem can be related to the client’s hardware and the bandwidth. Apart from these, there are few other factors that can affect the page performance.

    As we all know, the smaller the file size, the better the performance. Here are a few elements that can reduce the HTML file size, which will improve the page load performance in the browser.

    1. Avoid lot of images. When a browser requests a page, it makes N number of calls to the Web server to display N number of images. This will slow down the page load process. When you can’t avoid multiple images, try to show the images as thumbnails.
    2. Frames are another elements that will slow down the load process. For frames also, there will be N number of requests to display N number of frames.
    3. If you can avoid tables, that's good news. But we can’t always do that, so try to avoid nested tables. This will boost the load performance.
    4. If you know your users, you can design better pages. Well, this is not possible in the Internet. But, if you are developing an Intranet product for a corporation, then the corporation will have a standard browser. For example, if the corporation’s standard browser is a 4.0 browser then you can avoid some complex tables and you can use Cascading Style Sheets to position your HTML elements.
    5. Avoid redundant tags. Let's take the following example:
      
      	
      	<Body><br>
      	<P><font face="Verdana" size="4"><br>
      	</font></P><br>
      	<P><font face="Verdana" size="4"><br>
      	</font></P><br>
      	<P><font face="Verdana" size="4"><br>
      	</font></P><br>
      	</Body><br>
      	
      
      
      You can avoid the <font> tag

      Source 2:

      
      
      	<Body><br>
      	<font face="Verdana" size="4"><br>
      	<P><br>
      	</P> <br>
      	<P> <br>
      	</P><br>
      	<P> <br>
      	</P><br>
      	<font> </Body><br>
      	
      
      
    6. Avoid lot of jazzy comments. This will reduce the file size. I hate to leave comments in the HTML page. This will allow the others the view my page and understand my style.
    7. Avoid long file names and use relative path names to identify other files.
    8. Even you can reduce the formatting and indenting for the HTML page. This will minimize the page size.
    9. now you WYSIWYG HTML editor. Some of the WYSIWYG HTML editors will put lot of unwanted HTML tags in the page. So, it’s a good idea to clean up the unwanted tags, once you have designed your page with the WYSIWYG editor.
    10. Avoid Java Applets in the HTML pages, when they are not needed. For example, if you are only using the Java Applets for animations, then try to use animated gif files or a Flash animation. They are faster than Java Applets.

    ASP Page Performance

    1. Reading from the object variable is always slower than reading from the local variable. So, if you are going to read from the object variable often, then store it in a local variable and access it. Slower:
      
      if Myobj.Value = 0 then
      Do something
      elseif Myobj.Value > 0 then
      Do something
      elseif Myobj.Value < 0 then
      Do something
      end if
      
      
      Faster:
      
      MyVar = Myobj.Value
      
      if MyVar = 0 then
      Do something
      elseif MyVar > 0 then
      Do something
      elseif MyVar < 0 then
      Do something
      end if
      
      
    2. If you are using VBScript 5.0 or later, then you can use the With ... End With statements.

      Slower:

      
      Myobj.FirstName = "Srinivasa"
      Myobj.LastName = "Sivakumar"
      Myobj.City = "Chicago"
      
      
      Faster:
      
      With Myobj
      	.FirstName = "Srinivasa"
      	.LastName = "Sivakumar"
      	.City = "Chicago"
      End with
      
      
    3. Before doing a bulky ASP code processing, you can check to make sure Response.IsClientConnected. If not, don’t process the page. This will reduce the load on the server.
    4. As always, avoid session variables because each ASP page runs in a different thread and session calls will be serialized one by one. So, this will slow down the application. Instead of session variables you can use the QueryString collection or hidden variables in the form which holds the values.
    5. Still you think you can't avoid the session variables. And if you have lot of session variables, then it is better to use the dictionary object.
    6. Disable the session access, if possible, with <%@ EnableSessionState=False %>.
    7. Enabling buffering will improve the performance, like Response.Buffer=True.
    8. Wrap all your data-access code inside a COM component. In this way you can take advantage of speed of the compiled and multithreaded. As you know, creating a database connection takes lots of system resources and time. You can avoid this time-lag by taking advantage of the connection pooling, when your component runs inside the Microsoft Transaction Server (MTS). MTS is a Windows NT-based technology that when used with Distributed COM (DCOM), lets you build COM objects that are more easily distributed across a network than when using DCOM alone
    9. Avoid multiple calls to the COM component. For example, if you want to write 10 values to a COM component, you will do it with 10 calls to the component. However, if you can do it with one call, then that will improve the performance.

      Slower:

      
      Myobj.FirstName = "Srinivasa"
      Myobj.LastName = "Sivakumar"
      Myobj.City = "Chicago"
      
      
      Faster: Instead of exposing 3 properties from the COM component, you can expose a single property called “Value,” and you can take advantage of the single call.

      Let’s see how the code will look in the COM component:

      Declare the private variables to hold the values of the properties. Declare three more constants to hold the property value position in the array.

      
      Option Explicit
      
      'Local variables to hold property values
      Private mvarFirstName   As String
      Private mvarLastName    As String
      Private mvarCity        As String
      
      'Property Value Constants
      Private Const CN_FirstName = 0
      Private Const CN_LastName = 1
      Private Const CN_City = 2
      
      
      Add the “Value”property procedure.

      Public Property Let Value(ByVal vData As Variant)

      
          On Error GoTo ErrHand
      
          'Check if the parameter value is an array
          If IsArray(vData) = False Then
              Err.Raise 100, App.Title & " - Property Let: Value", "Invalid property value. An array is expected."
              GoTo CleanExit
          Else
              mvarFirstName = vData(CN_FirstName)
              mvarLastName = vData(CN_LastName)
              mvarCity = vData(CN_City)
          End If
      
      CleanExit:
          Exit Property
      ErrHand:
          Err.Raise Err.Number, Err.Source, Err.Description
          Exit Property
      End Property
      
      
      Here is how you will call the method from the ASP page.
      
      Myobj.Value = Array("Srinivasa", "Sivakumar", "Chicago")
      
      
      Even you can write the Get property procedure to pass the data from the component to the ASP application with a single call.

      Note: Always have error handlers in all your functions, subs, properties, etc. This will avoid the whole system going down when an error occurs in the component. Even an error in a component could bring all the applications down in the same memory space. It could bring the Internet Information Server (IIS) down, if the component is running in the IIS memory space.

    10. Never, ever declare a COM component such as an ADO connection object with the application or session scope. This will also hit the performance because of the threading each call has to be marshaled between threads.
    11. The Apartment-Threaded COM component objects are only good for page scope. If you want to access the COM objects across the page, then consider the free-threaded or both threaded components.

      Note: You can only develop Apartment-Threaded components in Visual Basic. If you are serious about the free-threaded component, then you have to develop them in VC++ or in Java.

    12. Do not use OnStartPage and OnEndPage methods to access the ASP intrinsic. These methods are provided for legacy support with IIS 3. Instead of this, use the ObjectContext with Implements keyword.
    13. When you are accessing the component across the process or machine, pass the variables to the objects as By Val. This will reduce the Marshaling overhead.
    14. When you have more than 100 lines of code in ASP, it is advisable to move that code to a COM component. ASP scripts are interpreted at run time and COM components are compiled.

      Note: There is a time-lag for the component to be initialized, up and running. This could also affect the application performance, so be careful before making the decision between the ASP script and COM component.

    15. Never use components such as Microsoft Word or Excel to manipulate the data. They are out-of-process components and they are not optimized for performance.
    16. The other advantage of the component over the script is early binding vs. late binding.
    17. As a Web developer, we always like to create a large Include file that will include all the global code and constants. The problem with this approach is some of the code or the declaration will not be used in every page. So for each and every page these Include files will be processed and this will definitely slow down the page performance.
    18. Avoid multiple Request.Write statements and group them in to few. Slower:
      
      'Add a default Select Word
      Response.Write " <option value=""0"">(Select a Program Manager)</option>"
      
      ¨	Do While Not objRs.EOF
      Response.Write " <option value=" & objRs!ProjManKey & ">" & objRs!ProjMan & "</option>"
      objRs.MoveNext
      Loop
      Response.Write "</font> </select>"
      
      
      Faster:
      
      Dim strHTML
      
      'Add a default Select Word
      strHTML =  " <option value=""0"">(Select a Program Manager)</option>"
      
      Do While Not objRs.EOF
      strHTML = strHTML & " <option value=" & objRs!ProjManKey & ">" & objRs!ProjMan & "</option>"
      objRs.MoveNext
      Loop
      strHTML = strHTML &  "</font> </select>"
      
      Response.Write strHTML
      
      

    Network Bandwidth Issues

    1. In most cases network performance can ruin the ASP performance. Use 10/100 network cards for better performance.
    2. If your Web server and the database server are running in the same server, then it is advisable to move them into different servers.
    3. Even you can introduce a new middle-tier server to handle the COM components with MTS. This decision totally depends on the load on the Web and MTS servers.

    Database Issues

    Well, a good database design can contribute a lot to the performance. Database design issues are out of the scope of this article. Let’s see few points that could improve the database performance.

    1. Whenever you access the database, avoid the dynamic SQL and use stored procedures or database views. Before finalizing the SQL statement for the stored procedure or view, analyze the SQL query and make sure it is optimized, and also make sure that it uses the proper indices for record scanning.
      Note: If you are using SQL Server 7 or later. then you can take advantage of the visual output of the “Query Analyzer.”
    2. The join type used in the SQL statement will also increase or decrease the performance of the query.
    3. When using the ADO Recordset objects, use the proper cursor type and lock type. For example, if you are going to fill a combo box, then you can use the cursor type adOpenForwardOnly and lock type adLockReadOnly.
    4. Sometimes allocating appropriate database buffers will increase the performance. For example, if you are working with the Oracle database, for each connection you should have three sessions open. If you can fine-tune these things, you’ll get drastic performance increase.
    5. If your site has lot of hits and your server can’t handle the entire load, then replicate the ASP application and the database.

      Note: While designing the database, you have to make appropriate design considerations for database replication. When we are replicating the databases, few elements will not be replicated. For example, if you are using Oracle as the database server, Database Sequences will not be replicated. So, if you are rely on Database Sequences for your primary key, then you are in trouble.

      Summary

      When we talk about ASP performance, there are lots of factors and I have discussed each of them in detail. But don’t think that if you can fix all these factors, your ASP performance will increase. All these tips will not suit each and every ASP application. We have to consider them in application by application basis.

      Well, make some time to read the book “Microsoft Internet Information Server Resource Kit” from MS Press.

      Try these following for more information:

      Improving Web Site Performance
      Server Performance
      Microsoft Web Capacity Analysis Tool
      Simulating Cookies with the Munger

      Happy programming!

      About the Author

      Srinivasa Sivakumar is a software consultant in for TransTech, Inc., based in Chicago. He specializes in VB, SQL Server, MTS, and ASP. In addition to reading, he likes to readand watch Tamil movies and listen to Tamil soundtracks. He can be reached at srinivasasivakumar@india.com.

  • Rate This Article
    Not HelpfulMost Helpful
    1 2 3 4 5
    Supporting Products/Tools
    XCache
    XCache combines dynamic content caching technology with content delivery network (CDN) support options, file compression and a whole lot of manageability features to help e-businesses deliver superior web site performance and reliability. You'll appreciate the administrative ease, your visitors will appreciate increased page delivery speed.
    [Top]
    XCompress
    XCompress works by compressing outgoing text between the Web server and the client. Page response times may improve by a factor of three or more while overall bandwidth use can drop by two thirds or more.

    XCompress runs on Windows 2000 and Windows NT 4.0 and is tightly integrated with Microsoft Internet Information Server (IIS) with MMC and COM interfaces.

    [Top]
    XTune
    XTune 2.0 is the most powerful tuning application for IIS 4 or IIS 5 ever conceived. Indispensable to the enterprise and straightforward, this web tuning tool allows you to configure hidden operating system, network, Active Server Pages and Internet Information Server settings for better performance, without any additional hardware or software.

    This version scans your system more deeply, offering more performance-enhancing recommendations and greater insight into your web architecture. The Performance Wizard guides and teaches you throughout the complete tuning process, so you can learn while making your box run better than ever.

    Purchase here.

    [Top]
    Other Articles
    Aug 25, 2005 - Performance Monitoring in SharePoint Portal Server 2003
    Performance monitoring helps organizations identify performance bottlenecks. The problem is that with so many performance numbers available, how do you know which ones to watch? This article helps you identify which are the critical performance counters in a SharePoint Portal Server environment and explains how to monitor them. By monitoring performance regularly, organizations can recognize performance trends as they develop and prevent problems before they get out of hand.
    [Read This Article]  [Top]
    Aug 12, 2004 - Middle-Tier Hosting: Enterprise Services, IIS, DCOM, Web Services, and Remoting
    There is broad-reaching debate about remoting, Web services, Enterprise Services, and DCOM. In short, it is a debate about the best technology to use when implementing client/server communication in .NET. Rocky Lhotka shares his thoughts on the issue while offering clear explanations of basic application architecture terminology.
    [Read This Article]  [Top]
    May 18, 2004 - ASP.NET 2.0 Caching Features
    This article examines some of the new and exciting caching features in ASP.NET 2.0 and shows how to implement them in Web applications.
    [Read This Article]  [Top]
    Feb 12, 2004 - Case Study: Match.com
    When it came time to find a technology for its massive upgrade, Match.com chose .NET. Has the online dating service's partnership with Microsoft been as successful as the relationships it has established for many of its millions of members? Read on ...
    [Read This Article]  [Top]
    Jan 15, 2004 - Database Performance Philosophy
    Longtime 15Seconds discussion list member Tore Bostrup offers valuable advice on designing databases and applications for efficient querying.
    [Read This Article]  [Top]
    Dec 29, 2003 - Caching Oracle Data for ASP.NET Applications
    Narayan Veeramani shows how ASP.NET developers can improve application performance by caching data stored in an Oracle database and keeping the cached data in sync with the data in the Oracle database.
    [Read This Article]  [Top]
    Dec 2, 2003 - Leveraging MSMQ in ASP.NET Applications
    Ever developed a Web application that requires extensive processing? Ever had long running Web pages that often time out in the browser? Greg Huber reveals a simple technique that uses Microsoft Message Queuing (MSMQ) and the System.Messaging framework to handle long running Web processes.
    [Read This Article]  [Top]
    Mar 14, 2002 - Web Site Compression
    As IT professionals try to reduce the cost of operating their Web sites, they should consider reducing the amount of bandwidth usage. Learn how to successfully compress your HTML output and save money on your monthly bandwidth.
    [Read This Article]  [Top]
    Feb 6, 2002 - The Just Two Theory on Web Servers
    Maintaining a large Web farm is both costly and unnecessary. Learn how to reduce your Web farm to just two servers in this controversial article by Wayne Berry.
    [Read This Article]  [Top]
    Aug 14, 2001 - NT Authentication's Impact on Connection Pooling
    Steve Witkop examines OLE DB and ODBC connection pooling when used with Microsoft NT LAN Manager Web server authentication.
    [Read This Article]  [Top]
    Mailing List
    Want to receive email when the next article is published? Just Click Here to sign up.

    Support the Active Server Industry



    JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers