Solved

Why stateless components in COM+???

Posted on 2002-04-23
3
689 Views
Last Modified: 2013-11-25
Hi. I keep reading in a lot fo sites that you cannot maintain info state on a component running in COM+. However, given that VB threading model doesn't allow COM+ to pool it's objects, I see no sense in having stateless components... Anyone can bring me a light on this?? I'm not doing stateless components unless it's really needed!!
0
Comment
Question by:Cuervo
3 Comments
 
LVL 7

Expert Comment

by:Z_Beeblebrox
ID: 6963064
Hi,

That is a common misconception. State can be maintained in a COM+ object within a transaction. So if you start a transaction in one method, then finish it in another, you can have state between those two methods and any methods called between them. As for the technical details about how you do this, I have never tried myself.

Zaphod.
0
 
LVL 18

Accepted Solution

by:
mdougan earned 100 total points
ID: 6963109
Well, you're both ignoring one of the main reasons that you would want to use COM+ in the first place, and that is scaleablity.

Let's say that you have 1000 users trying to use the component at the same time.  With Advanced Server and Site Server(?) it's easy to set up clusters of servers that can be load balanced.  But if you're busy maintaining state in a component, then that means you have to maintain the connection to a particular instance of the component running on a particular box.

If you design your components to be stateless, then each trip to the component can be redirected to the most available box.

Also, I've seen a number of people post questions here about transactions they have used to try to span multiple method calls not being rolled back properly.  While it might be theoretically possible, I don't think that it is as reliable as a stateless model where each call is a separate transaction.

I've used the stateless model on two large international enterprise applications with great success and reliability.

Here is a section of a white paper from Microsoft on COM+ application development guidelines that we followed pretty closely:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncomser/html/complus.asp

(download the complusprint2.exe self extracting zipped document)


Adopt a Stateless Programming Model on the Server
This design issue has been debated thoroughly in many channels and has been approached in different ways. Although there are many reasons to go for stateless designs, stateful design has its niche. However, correct software distribution methodologies suggest that for OLTP server operations (a shared resource/concurrent isolated activity environment) the stateless approach is optimal in most cases. They allow for an interdependent, easily cloned, design of services with transparent failover, easier load balancing, less resource contention, and easier management of transactional data.
In addition, a stateless approach is more linear in design and implementation than a stateful approach. This means that it reduces dependency on time-variant factors or method call sequencing, producing activities that are more isolated and providing a finer granularity for load balancing. It is easier to develop software from a single-user activity standpoint than it would be to deal with all the issues involved in state management.
More Information
Exceptional reasons to maintain a user/session/instance-specific state in a server object is when all of the below hold to a strong degree:
7      The data being kept is expensive or impossible to reacquire.
7      It has undergone a transformation that is too costly or impossible to perform on the client machine.
7      It has undergone a transformation that is too costly or impossible to redo on the client machine.
7      It is too expensive or impossible to transmit the state data to the client.
7      The data is not duplicated in an alternate transactional store.
If most of the above holds true, you have a strong candidate for a stateful server-side programming model. This might improve your performance but it will drastically reduce your concurrency and maybe your scalability.
At this point, you must ask yourself if this piece of data belongs in an OLTP-ish TP environment. You may evaluate alternate state management methods (storing to specialized databases) or transport mechanisms. Also, evaluate the benefits of asynchronous operations when dealing with this type of information.
How To
Make sure you have good state management approach in your server:
7      You do not have global variables that cache information in Recordsets, Collections, or Dictionaries. These will cause bottlenecks and failures.
7      Your classes have no class-level members (Private or Public variables) that have a lifetime beyond that of one method call. Use parameters on the functions instead of properties (network roundtrips are more expensive and network packets seldom have to be wasted because of larger numbers of parameters). In general, the only Private variables you will have are those initialized from constructor strings.
7      Your methods open connections to resources and close them immediately. All ADO objects that have been opened are closed, and all objects created are explicitly released by setting them to nothing.
7      You call ObjectContext.SetComplete/SetAbort before returning from the method.
References
Microsoft Systems Journal (MSJ): Q&A ActiveX/COM by Don Box (http://msdn.microsoft.com/library/periodic/period98/activex0398.htm)
0
 

Author Comment

by:Cuervo
ID: 6989905
Ok, that's something to follow

Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now