471,315 Members | 1,604 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,315 software developers and data experts.

Static Functions in Multi-user web app


Is there any performance considerations or any other concerns about having a
Class with private constructor and all static functions? One particular
function in question creates a few new instances of COM objects (through COM
Interop), and makes lots of calls to these unmanaged COM objects.
There's a small debate in our team if having this portion of code inside
static function is appropriate for this multi-user web application that will
probably server many simultaneous requests. Should this logic be inside an
instance class?

Feb 6 '06 #1
6 1816
I would imagine you need to make sure that accesses to the COM objects are
thread safe, since you only have one instance of those. If you do, that may
end up being a bottleneck when you have many users hitting the system, which
would mean you need to make all your methods instance methods using separate
instances of the COM objects.

"WebMatrix" <We*******@discussions.microsoft.com> wrote in message
news:05**********************************@microsof t.com...

Is there any performance considerations or any other concerns about having
a
Class with private constructor and all static functions? One particular
function in question creates a few new instances of COM objects (through
COM
Interop), and makes lots of calls to these unmanaged COM objects.
There's a small debate in our team if having this portion of code inside
static function is appropriate for this multi-user web application that
will
probably server many simultaneous requests. Should this logic be inside an
instance class?

Feb 6 '06 #2
WebMatrix,

If the static function is not modifying state, then I don't see why not.
However, I do think that using the COM objects will be a problem. Not
because of the static nature of the functions, but you have to be sure that
you have set up the threading correctly to use COM objects in your project
(you need to set AspCompat = true in order for COM objects to work correctly
in ASP.NET, and you are going to take a little bit of a performance hit, I
believe).

Given all that, if your functions are static, and you are not modifying
any stored state, then there is no reason you can't do this. The problem
inherently doesn't come from whether or it is static or an instance method.
If you have to share the state between calls to the method (either static
state, or the state of the instance), and multiple threads are going to hit
it (like in a web environment), then you are going to have to synchronize
access to that resource.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"WebMatrix" <We*******@discussions.microsoft.com> wrote in message
news:05**********************************@microsof t.com...

Is there any performance considerations or any other concerns about having
a
Class with private constructor and all static functions? One particular
function in question creates a few new instances of COM objects (through
COM
Interop), and makes lots of calls to these unmanaged COM objects.
There's a small debate in our team if having this portion of code inside
static function is appropriate for this multi-user web application that
will
probably server many simultaneous requests. Should this logic be inside an
instance class?

Feb 6 '06 #3
The COM object itself has no state. All methods of this COM object are of
"request/response" nature. Each call to a static function creates COM objects
and destroy them when it's done with them. Am I understaning correctly that
each call to static function will work with its own instance of COM object
and its data? So thread safety would not be a problem?

"Marina Levit [MVP]" wrote:
I would imagine you need to make sure that accesses to the COM objects are
thread safe, since you only have one instance of those. If you do, that may
end up being a bottleneck when you have many users hitting the system, which
would mean you need to make all your methods instance methods using separate
instances of the COM objects.


Thank you for your reply. There's no
Feb 6 '06 #4
WebMatrix,

Yes, each call to the COM object will be safe, but you have to consider
the apartment model. You have to make sure that the calls are on pages/web
services where AspCompat is set to true, so that the apartment model can be
set up correctly.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"WebMatrix" <We*******@discussions.microsoft.com> wrote in message
news:17**********************************@microsof t.com...
The COM object itself has no state. All methods of this COM object are of
"request/response" nature. Each call to a static function creates COM
objects
and destroy them when it's done with them. Am I understaning correctly
that
each call to static function will work with its own instance of COM object
and its data? So thread safety would not be a problem?

"Marina Levit [MVP]" wrote:
I would imagine you need to make sure that accesses to the COM objects
are
thread safe, since you only have one instance of those. If you do, that
may
end up being a bottleneck when you have many users hitting the system,
which
would mean you need to make all your methods instance methods using
separate
instances of the COM objects.


Thank you for your reply. There's no

Feb 6 '06 #5

If the static function is not modifying state, then I don't see why not.
However, I do think that using the COM objects will be a problem. Not
because of the static nature of the functions, but you have to be sure that
you have set up the threading correctly to use COM objects in your project
(you need to set AspCompat = true in order for COM objects to work correctly
in ASP.NET, and you are going to take a little bit of a performance hit, I
believe).

Given all that, if your functions are static, and you are not modifying
any stored state, then there is no reason you can't do this. The problem
inherently doesn't come from whether or it is static or an instance method.
If you have to share the state between calls to the method (either static
state, or the state of the instance), and multiple threads are going to hit
it (like in a web environment), then you are going to have to synchronize
access to that resource.

Hope this helps.

Thank you. It does help.

Right, no state between the calls. Like I said in a previous post; it's
"request/response" style calls.
but you have to be sure that you have set up the threading correctly to use COM objects in your project
(you need to set AspCompat = true in order for COM objects to work correctly
in ASP.NET


Could you elaborate or point to some URL.

Feb 6 '06 #6
Ok, I was a little mistaken, you can't really use AspCompat, that's only
for pages in ASP.NET. Rather, you have to host your controls in COM+. The
following KB article tells you how to do it:

http://support.microsoft.com/default...;en-us;Q303375
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"WebMatrix" <We*******@discussions.microsoft.com> wrote in message
news:01**********************************@microsof t.com...

If the static function is not modifying state, then I don't see why
not.
However, I do think that using the COM objects will be a problem. Not
because of the static nature of the functions, but you have to be sure
that
you have set up the threading correctly to use COM objects in your
project
(you need to set AspCompat = true in order for COM objects to work
correctly
in ASP.NET, and you are going to take a little bit of a performance hit,
I
believe).

Given all that, if your functions are static, and you are not
modifying
any stored state, then there is no reason you can't do this. The
problem
inherently doesn't come from whether or it is static or an instance
method.
If you have to share the state between calls to the method (either static
state, or the state of the instance), and multiple threads are going to
hit
it (like in a web environment), then you are going to have to synchronize
access to that resource.

Hope this helps.


Thank you. It does help.

Right, no state between the calls. Like I said in a previous post; it's
"request/response" style calls.
but you have to be sure that you have set up the threading correctly to
use COM objects in your project
(you need to set AspCompat = true in order for COM objects to work
correctly
in ASP.NET


Could you elaborate or point to some URL.

Feb 6 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by mflanagan | last post: by
2 posts views Thread by David | last post: by
10 posts views Thread by Simon | last post: by
18 posts views Thread by Ronald Bruck | last post: by
5 posts views Thread by Sam.Gundry | last post: by
14 posts views Thread by subramanian100in | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.