|
|||
|
Printable Version: Use the print command from the menu above to print this item. |
|
|
Web applications are based on client-server, request-response mechanisms. Performance of any moderate- to high-functional Web application is directly proportional to the architectural decisions and the technologies chosen to support it. Performance also depends on the architectural awareness of a programmer and his ability to address it from the inception phase of any Web-based application. The purpose of this paper is to discuss various aspects of enhancing performance of a Web-based application. The paper will provide illustrations and discussions to address these aspects. High-Level Architecture
The general flow of this architecture is as follows: The client (presentation layer) will request a URL. A Web server (distribution layer) will receive the request and carry the preliminary processing. Based on processing, the Web server will call the business logic layer. The business logic layer carries out further processing based on encapsulated business rules. The business logic will also interact with back-end database applications as well as any external applications. The business logic will return control to the Web server when processing completes. The Web server will send a response to the client. Minimal Code over the Wire Content Expiration and 304s Include Files and Graphics Optimization All images and cascading style sheets will be requested exclusively. It is more advisable to have one background image than four images joined to make one background image. It is advisable to have one CSS file than to have three for the same page. It is also recommended that gif and jpg files be optimized with the proper graphical tool. Using 256 colors instead of 32 will increase the file size. For example, saving the "Click Me" image with 32 colors (gif) gives 898 bytes of image size. But saving the same image with 256 (gif) colors will give 2.131K, and saving it as a jpg gives 2.83K of image size. Clearly, if the image quality does not suffer, to save network bandwidth the preferred file format should be gif with 32 colors.
Cascading Style Sheets Cross Boundary COM/COM+ calls In practice, accessing COM properties or methods can be deceptively expensive. Here is an example, showing some fairly common code (syntactically speaking): Foo.bar.blah.baz = Foo.bar.blah.qaz(1) If Foo.bar.blah.zaq = Foo.bar.blah.abc Then ' ... When this code runs, here’s what happens:
As you can see, this is terribly inefficient and slow. The fast way to write this code in VBScript is Set myobj = Foo.bar.blah ' do the resolution of blah ONCE Myobj.baz = myobj.qaz(1) If Myobj.zaq = Myobj.abc Then '... If you’re using VBScript 5.0 or later, you can write this using the With statement: With Foo.bar.blah .baz = .qaz(1) If .zaq = .abc Then '... ... End With Note that this tip also works with VB programming. Optimized Logging String Manipulation s = "<table>" & vbCrLf For Each fld in rs.Fields s = s & " <th>" & fld.Name & "</th> " Next While Not rs.EOF s = s & vbCrLf & " <tr>" For Each fld in rs.Fields s = s & " <td>" & fld.Value & "</td> " Next s = s & " </tr>" rs.MoveNext Wend s = s & vbCrLf & "</table>" & vbCrLf Response.Write s There are several problems with this approach. The first is that repeatedly concatenating a string takes quadratic time; less formally, the time that it takes to run this loop is proportional to the square of the number of records, times the number of fields. A simpler example should make this clearer: s = "" For i = Asc("A") to Asc("Z") s = s & Chr(i) Next On the first iteration, you get a one-character string, "A." On the second iteration, VBScript has to reallocate the string and copy two characters ("AB") into "s." On the third iteration, it has to reallocate "s" again and copy three characters into "s." On the Nth (26th) iteration, it has to reallocate and copy "N" characters into "s." That’s a total of 1+2+3+...+N which is N*(N+1)/2 copies. In the recordset example above, if there were 100 records and five fields, the inner loop would be executed 100*5 = 500 times, and the time taken to do all the copying and reallocation would be proportional to 500*500 = 250,000. That’s a lot of copying for a modest-sized recordset. In this example, the code could be improved by replacing the string concatenation with Response.Write() or inline script (<% = fld.Value %>). If response buffering is turned on (as it should be), this will be fast, as Response.Write just appends the data to the end of the response buffer. No reallocation is involved and it’s very efficient. In the particular case of transforming an ADO recordset into an HTML table, consider using GetRows or GetString. If you concatenate strings in JScript, it is highly recommended that you use the += operator; that is, use s += "some string", not s = s + "some string" Miscellaneous
References "Designing Performance in to Your Web-Based Applications," IBM performance management and capacity planning services "Object Oriented Performance Testing of Web Applications" by Dr. B. M. Subraya and S. V. Subrahmanya, IEEE "Boosting App Server Performance," Application Development Trends, Vol 7, No II "E-Business Testing: User Perceptions and Performance Issues" by Andreas Rudolf and Raniner Pirker, IEEE 0-7695-0825-1/00 "Performance Testing E-Commerce Web Systems" by Mike Hagen. Presentation paper, Vanguard Group, 3 May 2002 "Load Testing for E-Confidence," Segue software "Scaling the Web" by Daniel. A. Menasce, George Mason University About the Author Arvind Rajaram is a senior programmer analyst. He has more than five years' experience in software development, quality assurance, and automated testing. He has a master's degree in engineering from Brooklyn Polytechnic, NY, and has worked as a performance engineer for several projects. You can contact Arvind at arvindrajaram@yahoo.com. Anand Desai is a programmer analyst who has been developing client-server and Web applications for the past three years on various platforms. He has a master's degree in MIS from Long Island University.
|
|
||||||||