How to enhance the performance of ASP program (2)

xiaoxiao2021-03-06  109

Skills 6: Smart using session objects

Session has several defects when used on busy sites. Busy means: There are hundreds of pages per second on site, or have thousands of access users. This trick is very important for those sites that require a strong level of extension, that is, these sites: they use multiple servers to complete data loading or handle a lot of fault tolerance. For small sites, such as internal network Intranet, Session is very pronounced.

Reebred again, the ASP automatically creates a session for each first click on the web server, each session occupies approximately 10 kb memory, and the survival is 20 minutes by default.

Using the SESSION's biggest problem is not performance, but scalability, session cannot span multiple web servers, once a session is created on a server, its data resides there. This means that if you use session on the Web, you have to design a policy for each user who stores the SESSION server. This is why users "stick" on the web server, the term "sticky sessions" comes from this. If the web server encounters an obstacle, "Stuck" user will lose their session status because the session is not retained on the disk.

Performing sticky session strategy includes hardware and software solutions, such as Windows2000 Advanced Server

NetWork Load Balancing and Cisco's Local Director, but exchange these to sacrifice certain scalability.

Application objects cannot cross the server. If you need to share and update Application data in a web group, you need to use the background database. However, read-only Application data is still useful in the Web group.

Many of the tasks requires a strict site to set up at least 2 web servers, so when designing strict tasks, you need to perform "Sticky Sessions", or simply avoid using Session, and you can also take other saved user status to Management technology of independent web servers.

If you don't use Session, you must confirm that you turn it off, which can be implemented via the Internet Service Manager. If you decide to use session, you can minimize their impact in several ways.

You can move content that doesn't require session (such as a Help Screen, Accessor Area, etc.) to the standalone ASP application that is turned off in the session. On the foundation page, you can give an indication to the ASP, so it doesn't need to use session. Add the following code directly to the header of the ASP page:

$ # @ 60;% @ enablessionsState = false% $ # @ 62;

One of this instructions is very good? Interpretation is an interesting issue in the frame structure. ASP ensures that only one request from Session is executed at a time, which ensures that if the browser requests multiple pages for a single user, only one ASP request can accept the session at that time, so avoid accessing the session object. Multithreaded problem. Unfortunately, all pages in the frame structure will be displayed in a continuous order, one pick one, not simultaneous, so users must wait for a long time in order to see the entire framework. The rule is: If a certain frame page does not use session, you must tell the ASP to use @ enablessionsState = false.

In addition to using the session object, there are many other severings of other management session. For small quantities (less than 4KB), we usually recommend using cookies, query string variables, and form hidden domains. For large amounts of data like shopping carts, the background database is the most appropriate choice. Tips 7: Load the code into the COM object

If you want to write a lot of VBScript or JScript, in order to make a performance, you can write the code as a COM object and compile. Compiling code is basically a fast than the interpretative code, and the compile component object can access other COM objects via "Early Binding", which is more effective than calling components in the script.

There are many advantages to do this:

COM objects are beneficial from the independent expressing rules of the business rules to make the code reuse may have many developers to find VB, C or Visual J write programs, which is more prone to debugging COM objects than ASP, including initial development time and Need for different programming skills. Note that a small amount of ASP code is a COM object component will not be beneficial, but it may cause loss of performance, thereby losing the advantage of compiling code. How to combine the use of ASP scripts and COM objects to achieve optimal performance is a test problem. We note that Microsoft has improved the performance of scripts and ado on Windows 2000 / IIS 5.0, whereby the introduction of the IIS5.0 version reduces the performance advantages of compiling code.

Tips 8: Using Option Explicit

To use Option Explicit definition in the ASP file, and place it to the head of the ASP file, forcing developers to declare all variables before use. Many programmers believe that this is very useful when application debugging, because it avoids possible possible type variables and creating new variables.

Perhaps more importantly, the declared variable is much faster than non-declared variables.

Skill 9: Copy often used data to the script variable

When you use a COM object in the ASP, you should copy the frequently used object data to the script variable, which reduces the method call to the COM object. These calls are relatively expensive than access script variables. Use this technique when you access the Collection and Dictionary objects, also reduces expensive lookup operations.

Typically, if you need to access object data over one time, data should be placed in a script variable, and the object data is mainly the request variable (form and query string variable). For example, the site wants to pass a query string variable called UserID, assume that it will be referenced 12 times in a special page, so no need to call Request ("UserID") 12 times, as long as the header of the ASP page is distributed to UserID one Variables, then use it in the page, which saves 11 calls for 11 COM methods.

In practice, access COM attributes or methods is very expensive, the following example shows universal code:

FOO.BAR.BLAH.BAZ = foo.bar.blah.qaz (1)

If foo.bar.blah.zaq = foo.bar.blah.abc dam

After the code is executed, the following things happen:

1. Variable FOO is treated as a global object

2. Variable Bar is treated as a member of FOO

3, the variable Blah is treated as a member of foo.bar

4, variable QAZ is treated as a member of foo.bar.blah

5, call foo.bar.blah.quaz (1)

6, then perform step 1 to 3 to decompose Baz

7. Decompose Baz as a member of foo.bar.blah

8, then perform step 1 to 3 to decompose ZAQ

9, execute step 1 to 3 once decomposition ABC

As shown above, this is very no efficiency and very slow. The faster method is to write code with VBScript, as follows: set myobj = foo.bar.blah do the resolution of Blah onCE

Myobj.baz = myobj.qaz (1)

IfObj.zaq = myobj.abc dam

If you use VBScript 5.0 or higher, you can use the with statement:

With foo.bar.blah

.baz = .qaz (1)

If.zaq = .abc dam ...

...

End with

Note: This trick can also be applied in VB programming.

Tips 10: Avoid redefining arrays

Do not define arrays again. Considering performance issues, if the physical memory size of the machine is not enough, it is best to set the initial size of the array according to the worst case or the best condition, and then redefine it.

The following code shows the use of DIM and RedIM:

<%

DIM myArray ()

Redim MyArray (2)

MyArray (0) = "Hello"

MyArray (1) = "Good-bye"

MyArray (2) = "FAREWELL"

...

Some Other Code Where You End Up NEEDING More Space Happens, Then ...

Redim Preserve MyArray (5)

MyArray (3) = "more stuff"

MyArray (4) = "Even more stuff"

MyArray (5) = "yet more stuff"

%>

Simply define an array initial size to be a suitable size, instead of increasing arrays with Redim. So perhaps waste some memory (if you don't use space completely), but win the speed.

转载请注明原文地址:https://www.9cbs.com/read-103891.html

New Post(0)