Share via


Maximizing the Performance of Your Active Server Pages

 

Nancy Winnick Cluts
Based on a presentation by Philip Carmichael
Microsoft Corporation

March 4, 1998

Contents

Introduction What Is ASP? Know Thyself ActiveX Server Components and ASP Server Scriptlets ActiveX Server Components and ADO Database Concerns SQL Server Performance Testing Use Sessions Wisely Stress and Performance Counters ASP Tips and Top Ten List Additional Resources Summary

Introduction

Active Server Pages (ASP) provides a consistent, easy-to-use interface to Web-based clients. With ASP, you can connect your user interface (HTML) with business logic. ASP also provides a secure environment for Web applications that require transactions. This article will give you the information you need to maximize the performance of your ASP scripts. In this article we will discuss:

  • What ASP is
  • File standards
  • ActiveX® server components and ASP
  • Database concerns
  • Performance testing

This article is based on the presentation "Maximizing the Performance of Your Active Server Pages," (DWA 05) by Philip Carmichael at Web Tech·Ed, January 25-28, 1998, in Palm Springs, California. This presentation is available via NetShow. Check https://www.microsoft.com/training/seminars/wte.asp for details.

Microsoft will present additional Web-related technical-solution sessions in June at Tech·Ed 98 in New Orleans. See the Microsoft Events site at https://www.microsoft.com/usa/events/for details and registration information.

What Is ASP?

Active Server Pages (ASP) technology provides the environment in which you can run scripts on the server. If you can write HTML, you can create an ASP file. It's really that easy. Your ASP file is simply a file that can contain any combination of HTML, scripting, and calls to components. When you make a change to the ASP file on the server, you need only save the changes to the file—the next time the Web page is loaded, the script will automatically be compiled. Of course, to take advantage of ASP, you'll want to add features the script that will run on the server, such as database access or other network-related work.

ASP might be new to us, but it's being used widely on the World Wide Web. Aside from Microsoft Web sites (including the beloved MSDN Library Web site), sites such as NBC (http://www.nbc.com), Nasdaq (http://www.nasdaq.com), and even the maven of good things, Martha Stewart (http://www.marthastewart.com), take advantage of the power of ASP. If ASP is new to you, take a look at An Asp You Can Grasp: The ABCs of Active Server Pages for an overview.

Know Thyself

You can be a technically good scripter as far as correct syntax goes, but if you write script that is unreadable, it becomes unmaintainable. It is important to follow some kind of scripting file standard to maximize performance and ease maintenance.

Some things to keep in mind are:

  • Know your script language—Take advantage of your chosen scripting language's built-in functions and of ActiveX components.
  • Know your bottlenecks—You need to know where your users might run into a traffic jam. To minimize bottlenecks, debug script execution, copy collection values to local variables, and avoid the use of "expensive" commands in loops.
  • Be consistent—It will be easier to maintain the script later and makes your script cleaner.
  • Review standards documents—The Internet Information Server (IIS) Resource Kit includes a Standards Guide (soon to be available on the Web) that covers the standards you should follow for clean and crisp ASP script. When scripting ASP, use declaratives, type libraries, and Response.IsClientConnected. When using Visual Basic® Scripting Edition (VBScript), use Option Explicit. If you are using JScript™, take advantage of new features like regular expression support.

ActiveX Server Components and ASP

ASP supports the use of ActiveX server components. ActiveX server components provide a scriptable interface to your ASP via the Component Object Model (COM). If you are creating your own ActiveX server component for the server, don't give it a graphical user interface—the client won't see it. You have several options with components. You can reuse components that you have already bought or developed, you can buy new components, or you can build your own. There are pros and cons to each of these options. You can also select the scripting language you prefer when working with an ActiveX server component.

There are several components built directly into IIS for your use, including:

  • ActiveX Data Objects (ADO)
  • Message Queue Objects
  • File System Objects
  • Active Messaging Objects
  • Page Counter
  • Permission Checker
  • Content Rotator
  • Summary Information
  • Page Counter Component

Server Scriptlets

An easy way to get started with server components is to create server scriptlets. Scriptlets enable you to create small components of script that you can reuse across your site. This script can carry out common tasks such as accessing data, performing business logic, or participating in a transaction. Server scriptlets, which are reusable COM components written in script, are very simple to create via the popular scripting languages (that is, Perl, JScript, and VBScript). This technology is currently in beta test. To create one, check out the Microsoft Scriptlet Wizard.

ActiveX Server Components and ADO

ActiveX Data Objects (ADO) provides the commonly used mechanism for connecting to databases. These objects are used primarily by business components. Those of you familiar with Data Access Objects (DAO) and Remote Data Objects (RDO) should find the programming model for ADO familiar. ActiveX server components can use ADO to work with databases to provide content based on user preferences, geographical data, or any other criterion.

The article So Happy Together? Using ActiveX Components with Active Server Pages gives you more information about the basics of ActiveX components and ASP, and about using ADO with ActiveX server components.

Database Concerns

Most people will want to take advantage of information stored in a database for their Web sites. This goes for businesses, who may have customer lists or inventory, and for the well-connected home user who has their friends' contact information, CDs, and movies stored in a database (doesn't everyone have six machines on their home network?).

SQL Server

To get the most out of Microsoft SQL Server, the following tips apply:

  • Configure SQL Server's memory size adequately. There is a Knowledge Base article, Recommended SQL Server for Windows NT Memory Configurations (Article ID:Q110983) that can guide you in your configuration of SQL Server.
  • Be careful about protocol selection: Use named pipes if the SQL Server resides on the IIS machine and sockets otherwise. Detailed information about sockets and SQL Server can be found in the Knowledge Base article Connecting to SQL Server from TCP/IP Sockets Clients (Article ID:Q107647).
  • Let SQL do the work it was designed to do. It will join, sort, and group the data. Don't do this work yourself in other languages when you can write a query to do it for you.
  • Maintain your SQL Server by making backups and monitoring the logs it creates for you. This will help you detect problems and maintain the integrity of your data.
  • Use stored procedures for faster database access.
  • Use the SET SHOWPLAN ON command to see how SQL Server's query optimizer produces an access plan for returning data. This access plan includes the order in which the optimizer joins tables and what, if any, available indexes it will use.
  • Use indexes. Indexed database tables return query results faster than non-indexed tables.
  • Run Update Statistics on your server to help it keep track of the distribution of your data. Then, your SQL Server will make alterations based on this updated information.
  • Consider a data-source name (DSN) pool. This can be implemented as an array.

Performance Testing

Let's say that you are responsible for creating a Web site and decide to use Active Server Pages. Now let's say that your incredible team is down to a zero bug count and the site has remained stable for a week. You are thinking, "Ship it!" Of course, if you didn't test performance, you might find that your technically correct Web site is as slow as a slug. It's important that you take performance issues into consideration when you are designing your Web site. Trying to improve performance at the end of the development cycle can prove to be daunting—at that point, you really don't want to re-architect the site and you certainly don't want to rewrite every single page.

Use Sessions Wisely

Use sessions to save user data in memory when you will need to access that data frequently. Use persistent storage (ADO) to save data that you need to access less frequently. Do not use sessions where they are not needed—it will decrease your performance.

Stress and Performance Counters

There are some nifty tools that you can use to measure and stress your Web site. I know; why would I want my Web site to be stressed? Life is so difficult already; shouldn't we all just try to relax? Well, you won't be relaxed if visitors to your site send you nasty e-mail about its performance at peak connectivity time. I say, stress the Web page—not the Web author.

Take advantage of the Web Capacity Analysis Tool (available online at https://www.microsoft.com/workshop/server/toolbox/wcat.asp). This tool runs simulated workloads on a test Internet Information Server (IIS). By using this tool, you can test the responsiveness of your .asp files. After you run the tests, you can decide how you want to tune your .asp files. You can also take advantage of third-party testing tools to determine the performance of your Web site. Whichever tool you choose is up to you. Testing performance is a very worthwhile endeavor, so don't get hung up on which tool to use; just do it.

The IIS Resource Kit provides invaluable information on the performance tuning and design of your Web sites. The kit provides tools such as WCAT (described above), an HTTP monitor, a migration wizard, and a sign-up server.

Other quick tips for performance testing include:

  • Know the cost of external dependencies. If your ASP depends on content from external databases or files, know the time it takes to access these resources. Are there several other sites accessing the same databases? Should they be replicated?
  • Rate component throughput. If a component slows down performance, consider whether you should rework the component or use another one.
  • Simulate sessions, if used.
  • Determine the number of production machines you need. If you have too few machines, you may run into a severe bottleneck.

ASP Tips and Top Ten List

Here's a list of the top ten things to keep in mind when you are working with ASP. This list should get you started in the right direction. For a comprehensive explanation and list of tips, refer to the article 25+ ASP Tips to Improve Performance and Style.

  1. Design for success.
  2. Use application state for caching output.
  3. Create and modify ProcessorThreadMax registry value.
  4. Use system DSNs, not file DSNs or DSN-less DSNs.
  5. Enable buffering for all Applications.
  6. Use Microsoft Transaction Server "Library" Packages.
  7. Disable Session state, if not used.
  8. Use OptionExplicit with VBScript.
  9. Make ADO free-threaded if you use SQL Server.
  10. Modify the metabase AspScriptEngineCacheMax value.

Additional Resources

For more information about ASP, click the following links:

Summary

With the information you have now, you can create ASP files that include clean script that runs fast. Take advantage of the resources I've given you and don't forget to test! Keep checking this site as well as the IIS site for updated information about ASP and let us know what else you are interested in reading about. Of course, if we've covered it all flawlessly, you can tell us that, too!