ASP Skill Collection (Official Authority edition)-4

Source: Internet
Author: User
Skills Tip 9: out-of-process execution will sacrifice reliability
Both ASP and mts/com+ have configuration options that allow you to gain performance in return for reliability. This exchange should be understood when the application is built and deployed.
ASP Options
An ASP application can be configured to run in one of three ways. The term "isolation level" is introduced in IIS 5.0 to describe these options. Three isolation level values are low, medium, and high, respectively:
Low-level isolation. The isolation level is supported in all versions of IIS and is the fastest. It executes the ASP in the main IIS process Inetinfo.exe. If the ASP application crashes, IIS will also crash. (To restart Iis,web under IIS 4.0 The site administrator needs to use tools such as Inetmon to monitor the site, and if the server fails, a batch file will be run to reboot the server.) IIS 5.0 introduces a reliable reboot, which automatically restarts the failed server. )
Intermediate isolation. IIS 5.0 introduces this new isolation level, which is called out-of-process, because the ASP is running outside of the IIS process. In intermediate isolation, all ASP applications that are configured to run in "intermediate" will share a single process space. This reduces the number of processes that are required to run ASP applications outside of multiple processes on a single server. Intermediate is the default isolation level in IIS 5.0.
Advanced isolation. Supported by IIS 4.0 and IIS 5.0, advanced Isolation is also out-of-process. If the ASP crashes, the WEB server does not crash. The ASP application will automatically restart on the next ASP request. With advanced isolation, each ASP application that is configured to run as advanced runs in its own process space. This protects the ASP applications from interfering with one another. Its disadvantage is that it needs to establish an independent process for each ASP application. A lot of overhead is added when you need to host more than 10 applications on a single server.
So which option is the best? In IIS 4.0, running out-of-process applications can significantly affect performance. In IIS 5.0, much work has been done to minimize the performance impact of out-of-process running ASP applications. In fact, in most tests, an ASP out-of-process application in IIS 5.0 runs faster than an in-process application in IIS 4.0. In any case, the process (low isolation level) still produces the best performance on both platforms. However, if your hit ratio is relatively low or the maximum throughput is low, choosing a low isolation level will not do much good. So, unless you need each WEB server to process hundreds of or thousands of pages per second, there is no need to choose a low isolation level. Again, you should test a variety of configurations and determine which scenario is best for you.
Note: When you run an ASP application (intermediate or Advanced isolation) out-of-process, they will run in MTS on NT4, and they will run in COM + on Windows 2000. That is, they run in Mtx.exe on NT4, and they run in DllHost.exe on Windows 2000. In Task Manager, you can see these running processes. You can also see how IIS configures an MTS package or COM + application for an out-of-process ASP application.
COM Options
COM components also have three configuration options, although not exactly the same as ASP options. COM components can be: "Not Configured", configured as "Library applications", or configured as "Server applications." "Do not configure" means that components are not registered to COM +. Components will run in the process space of the caller, that is, they are in process. The library application is also a process, but benefits from COM + services, including security, transaction, and environment support. The server application is configured to run in its own process space.
As you may see, components that are not configured are slightly more advantageous than library applications. You may also see that the library application has a significant performance advantage over the server application. This is because the library application runs in the same process as the ASP, and the server application runs in its own process. The overhead of an internal process call is much greater than the overhead of an in-process invocation. Also, when you pass data, such as a recordset, between processes, you must copy all of the data between the two processes.
Disadvantages! When using COM server applications, if you want to pass objects between ASP and COM, make sure that the object implements "collection by value", or MBV. An object that implements MBV copies itself from one process to another. This is better than the other way, in another way, the object is left in the process that created it, while the other processes repeatedly call to create the process that uses the object. The disconnected ADO recordset is pooled by value and the connected Recordset is not. Scripting.Dictionary do not implement MBV and are not passed between processes. Finally, to tell another VB programmer is: MBV is not passed through the parameters ByVal obtained. MBV is implemented by the original component creator.
What to do?
If you want to complete your configuration with a reasonable exchange of performance and reliability, our recommendations are as follows:
On IIS 4.0, use the low isolation level of ASP and use MTS server packs.
On IIS 5.0, use the ASP's medium isolation level and use the COM + library application.
These are general guidelines; Typically, companies run ASP at the middle or high isolation level, while a single purpose WEB server can run at a low isolation level. Weigh the tradeoffs and decide on your own configuration to meet your needs.
  
   Tip 10: Explicit Use options
Explicitly use the option Explicit in an. asp file. This instruction, which is placed at the beginning of the. asp file, forces the developer to declare all variables to be used. Many developers think this helps debug the application because it avoids the error of typing the variable name and inadvertently creates a new variable (for example, myxlmstring= ...). Rather than myxmlstring=).
Perhaps more importantly, the declared variable is faster than the undeclared variable. In fact, when the script runs, it is referenced by name every time you use an undeclared variable. The declared variable is assigned an ordinal at compile or run time. In this way, the declared variable is referenced by that ordinal. Because the option Explicit enforces variable declarations, it is guaranteed that all variables are declared and fast access is achieved.
  
   Tip 11: Use local variables in subroutines and functions
A local variable is a variable declared in a subroutine and function. In subroutines and functions, local variable access is faster than global variable access. Using local variables can also make your code clearer, so use local variables whenever possible.
  
   tip 12: Copy common data to a script variable
When you access COM in ASP, you should copy the commonly used object data into the script variable. This will reduce the invocation of COM methods, which are relatively expensive compared to accessing script variables. This technique can also cut down on expensive lookups when accessing Collection and Dictionary objects.
In general, if you plan to access object data more than once, put the data in a script variable. The main goal of this optimization is the Request variable (Form and QueryString variables). For example, your site might pass a querystring named UserID. Suppose the UserID variable is to be referenced 12 times in a particular page. Do not call request ("UserID") 12 times, and assign UserID to a variable at the beginning of the ASP page. The variable is then used in the page. This saves 11 times of COM method calls.
In practice, accessing COM properties or methods is a cumbersome process and a lot of overhead. Here's an example, which is just some fairly common code (syntactically):
Foo.bar.blah.baz = Foo.bar.blah.qaz (1)
If Foo.bar.blah.zaq = Foo.bar.blah.abc Then ' ...
When you run this code, the following events occur:
Variable Foo is resolved to a global variable.
The variable bar is resolved to a member of Foo. This will result in a COM method call.
The variable blah is resolved to be a member of the Foo.bar. This also produces a COM method call.
The variable Qaz is resolved to be a member of the Foo.bar.blah. Yes, this will also produce COM method calls.
Call Foo.bar.blah.quaz (1). Another COM method call was generated. Do you understand this picture?
Performing steps 1 through 3 will resolve the Baz again. The system does not know whether the call Qaz changes the object model, so steps 1 through 3 must perform the parse Baz again.
Resolves the Baz to a member of the Foo.bar.blah. for attribute placement.
Perform steps 1 through 3 again and parse Zaq.
Perform steps 1 through 3 again and parse ABC.
As you can see, this is very scary and inefficient (and very slow). The quick way to write this code in VBScript is:
Set myobj = Foo.bar.blah ' Parse for blah
Myobj.baz = Myobj.qaz (1)
If Myobj.zaq = Myobj.abc Then ' ...
If you are using VBScript 5.0 or later, you can use the WITH statement to write this code:
With Foo.bar.blah
. Baz =. Qaz (1)
If. Zaq =. ABC Then ' ...
...
End With
Please note that this technique is also effective for VB programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.