Whether your component is used over the Internet or an intranet, it will need to respond to simultaneous calls. The way your component responds to simultaneous calls is largely determined by your choice of threading model. This choice will have significant implications on the component's responsiveness, particularly in large volume Internet scenarios.
Your options for threading models are:
Although it is possible for you to use any of the four threading models, it is recommended that you develop your components with either the Apartment or Both model. There are serious performance limitations with the Single and Free models. For a detailed explanation see the following:
and
You can use the Both threading model for all types of ASP components. All Both-threaded components should use the COM Library function CoCreateFreeThreadedMarshaler to create a free-threaded marshaler object. If you aggregate the free-threaded marshaler object, you can make calls between threads without any marshaling or thread switches. For more information on free-threaded marshaler objects, see the COM and ActiveX Object Services section.
If you build a Both-threaded component that does not aggregate the free-threaded marshaler object, you will only be able to dynamically assign the component application scope if the AspTrackThreadingModel configuration property is set to 1 (True). By default this property is set to 0 (False). For example, if the component MyComponents.Comp1 supports the Both threading model, but does not create a free-threaded marshaler object, the following code will generate a run-time error unless AspTrackThreadingModel is set to 1 (True).
Set Application("Obj1") = Server.CreateObject("MyComponents.Comp1")
Dynamically assigning MyComponents.Comp1 to session scope would not cause an error, however, it would severely impede performance for the duration of the session. Assigning this component to either application of session scope with the <OBJECT> tag would also have a negative impact on performance.
The only disadvantage of building components using the Both model is that it does not allow for serialization of calls to the component. This means that your component will need to guarantee thread safety. Building in thread safety may slow down your development time, but will make your component more suitable for use in session or application scope.
You can use the Apartment model for components with page or session scope. However, when you create Apartment model components in a session, the session is locked down to a single thread. This slows access time.
You should not use the Apartment threading model for components that you plan to give application scope. Creating an instance of an Apartment model object with Server.CreateObject will generate an error. For example, if in the following script MyComponents.Comp2
is Apartment-threaded, the script would generate an error.
Set Application("Myapp") = Server.CreateObject ("MyComponents.Comp2")
If you place an Apartment-threaded component in an application with the <OBJECT> tag, it will not generate an error. However, it will cause access to be slow. In addition, if you develop a component with the Apartment model and give it application scope, it will run in the System security context, rather than the context of the current user, thereby making it unacceptable for scenarios which rely on Windows® security.