Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create Object performance

Status
Not open for further replies.

petersonv

Programmer
Aug 16, 2002
3
BR
Hi
I have a dll installed in a Windows2000 Server at COM+.
The dll was installed in Windows98 clients with an application proxy.
The problem is when I use the CreateObject command to access my dll's classes in the Server. It has a low performance.
Is there any way to improve the creation of object?

thank's peterson

 
Welcome to COM. Performance degrades drastically the further you get, in a logical way, from the application.

If you have a HUGE registry using the the following syntax might save you a nano second

DIM j As Project1.Class1
Set j = New Project1.Class1

because at compile time it will grab the CLSID of referenced component type library when you compile.
If you use CreateObject your application, actually the VB Runtime, queries the registry at run-time the map the ProgId to the CLSID. The ProgID being the "Project1.Class1"

Both of these will use Early binding as long as you declared your object as a specific interface type.

Performance of COM objects on the server more enhanced by design then a few keywords you may use in programming

1) Reference the COM+ Services Type Library in your project and use the ObjectContext to control state
2) Make your objects stateless and call SetComplete() or SetAbort at the end of a method
3) pass ByVal when ever possible
4) don't pass objects, Recordsets are an exception but read up on them to understand why
5) create your object library as Apartment threaded.

There is just a few tips to get you started
 
Hello...
My dll have several classes.
If I'll create all classes in load of program and keep the objects in global variables, do you think that I can resolve the performance of creation?
I'm afraid that it would not be good for the client and the server, because all objects will be in memory.
When the classes are inside of vb project, I perceived that the program run faster. But I think that it is better to have a dll than private classes inside application.

What do you think about this?

Thank's perterson
 
1)If I'll create all classes in load of program and keep the objects in global variables, do you think that I can resolve the performance of creation?

This isn't a bad thing IF your objects are made stateless. As client side you are just holding a reference to the interface. No state is being maintained client side and since the objects are stateless serverside Just In Time Activation can be used. Thus you may find that even though you have 50 client apps out there only a few objects exsist on the server becasue not all the client apps are actually executing object code as the exact same time.

2)When the classes are inside of vb project, I perceived that the program run faster.
This is not just you thinking they are faster. Inprocesses objects are faster, then out of process (ActiveX.EXEs) on the same machine are slightly slower and remote process (COM objects on other machines) is the slowest.

Speed difference between a Class in your VB program and a Class in a Inprocess DLL is the same. So you can bundle them up in a DLL and have them run client side if that is what you want to do. Reason to have objects run on a MTS server can be any of the following and more.
1) Connection Pooling
2) Just in Time Activation
3) Security
4) Easy upgrading
5) Better/Faster Hardware
6) Closer to data Source
etc


 
Hello...
I don't know if my objects are stateless.
What is a stateless object?
If I create my objects in load of program I think that there will be a object in the Server. But, after this If other client create the same objects, the Server will use the instances created before, right?

Thank's Peterson
 
Stateless objects are objects that don't have to remember what state they are in, funny enough, between method calls.

What does this mean?

Lets look at some code

Code:
  DIM x As Project1.Class1
  Set x = New Project1.Class1

'step A  Method1 does something.  To do its job it needs 2 pieces of information
  x.method1 sData, iData
.
.
.
'step B called 5 minutes later.  To do its job it needs 2 different pieces of information and a piece from the first call
  x.method2 sData2, dblData2, iData


Now those objects could be stateless in that everything method1 and method2 need to there jobs are passed to them at the time the method is called.
A non stateless object you might put those variables into properties and call the method without any parameters.

You might ask what the difference is. Well if Method1 and Method2 are called 5 minutes apart and they have to remember the properities between the calls then that is wasting RAM and possibly other resources on the server. Where the stateless object you send the method all the information it needs and when it is done the method can inform MTS/Component services and the object will be recycled.

What do I mean about being recycled. Well that object can be put in a pool and if another client requests a Project1.Class1 it can be given to them. You client still has a handle to a Project1.Class1 but the next time you call a method you may not actuall get the same one you had before. Since you are not relying on properties to still be set on the object you don't care.

Think of it like this.

You like pizza.
You want to go out on a night on the town but don't want to drive.
So you call the taxi company and say
&quot;Can I a taxi at 123 Jones road going to 25 Center Street&quot; <-Method call
the taxi company dispatches you a taxi.
Your out on the town for a few hours and ready to go home
So you call the taxi company and say
&quot;Can I a taxi at 25 Center Street going to 123 Jones road &quot; <-Method call2
You may or may not get the same taxi

During the time you are out that taxi was free to do other jobs for other people
your handle to the taxi company is the same (phone number)

It would be more expensive for you to hire a car and driver for the entire night.
Why pay for something when you don't really need it. That is what stateless objects
are about. A few object can service many clients just like a few taxi's can service
many people.

What do you loose? Well you can't just tell the taxi driver &quot;Take me home&quot; because
he/she does not know where your home is. In Just in Time Activation it would be like
even if you got the same taxi driver they have very bad memory and once they drop you
off they forget everything about you. So you must supply them with the info they
need to get you home, your address.

To make a object stateless you follow some guidelines.
1) no properties. Properties are soley for maintianing state.
2) no internat variables that must maintain value from one call to the next as this is maintaining state also
3) inform MTS/Component Services when you are done and the server can reuse the object. (This is like paying the taxi driver and letting them go)

Its a lot to take in an a big shift from conventional programming.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top