473,804 Members | 2,164 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Activator Class

Hi

I have used the Activator class a number of times in my Windows apps and
Windows Services and was thinking of using it again in one of my web
services that I have been developing. I have been told that this is a bad
idea as it will greatly affect the performance of my web service. So I have
been thinking about it and all my other apps use the Activator class to
instantiate objects that hang around for the uptime of the app on start up,
whereas my web service will be using it to create and object each time it
needs one. This makes me think (obviously) that, this is where the
performance hit will take place.

So my question is: I will still be instantiating an object each time I need
one directly so will the activator class add much of an overhead to this
anyway?

If anyone knows of any useful articles on this topic I will be quite
grateful.

Regards

Ian
Nov 17 '05 #1
7 2249
Ian Frawley wrote:
I have used the Activator class a number of times in my Windows apps and
Windows Services and was thinking of using it again in one of my web
services that I have been developing. I have been told that this is a bad
idea as it will greatly affect the performance of my web service. So I
have been thinking about it and all my other apps use the Activator class
to instantiate objects that hang around for the uptime of the app on start
up, whereas my web service will be using it to create and object each time
it needs one. This makes me think (obviously) that, this is where the
performance hit will take place.

So my question is: I will still be instantiating an object each time I
need one directly so will the activator class add much of an overhead to
this anyway?


The problem is simply that object instantiation with Reflection (which is
what Activator does) is much slower than direct instantiation of the same
object. In .NET 2, many things related to Reflection have been sped up
enormously, but I haven't explicitely tested the Activator to see if it's
one of the classes that work much faster now. But still, there's a great
overhead involved when creating objects dynamically.

Obviously, while this problem doesn't have anything to do with the type of
app you're writing, it'll be more pronounced the more objects you create
with this mechanism. You should probably think about two things: (1) are
you sure you really need to create all these objects dynamically? Wouldn't
there be a way around that? and (2) Could you cache and reuse objects that
you created once instead of creating them every time you need them?

Finally, the general warning: Don't just believe someone who says, "this
or that will be very slow." Things like these always depend on your exact
application, so you should make up your own mind based on some tests you
should do, as close to the final app as possible. Calculate the number of
objects you are going to create, simulate the complexity of the objects in
question, create a small test program and try it out!
Oliver Sturm
--
Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)

Nov 17 '05 #2

"Oliver Sturm" <ol****@sturmne t.org> wrote in message
news:xn******** ********@msnews .microsoft.com. ..

*snip*
The problem is simply that object instantiation with Reflection (which is
what Activator does) is much slower than direct instantiation of the same
object. In .NET 2, many things related to Reflection have been sped up
enormously, but I haven't explicitely tested the Activator to see if it's
one of the classes that work much faster now. But still, there's a great
overhead involved when creating objects dynamically.

Obviously, while this problem doesn't have anything to do with the type of
app you're writing, it'll be more pronounced the more objects you create
with this mechanism. You should probably think about two things: (1) are
you sure you really need to create all these objects dynamically? Wouldn't
there be a way around that? and (2) Could you cache and reuse objects that
you created once instead of creating them every time you need them?

Finally, the general warning: Don't just believe someone who says, "this
or that will be very slow." Things like these always depend on your exact
application, so you should make up your own mind based on some tests you
should do, as close to the final app as possible. Calculate the number of
objects you are going to create, simulate the complexity of the objects in
question, create a small test program and try it out!
Oliver Sturm
--
Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)


Hi

1st thanks for your reply.

I have been thinking about this quite allot and the fact that I am creating
objects on demand within a busy web service could be quite costly without
even using the Activator class. I have started thinking of possibly pooling
a set number of these objects to be used when required but the thought of
locking issues involved and also web clients sitting about until an object
becomes available is another concern. Either way I think possibly a more
elegant solution is called for.

Do you have any articles on caching objects for reuse?

Ian
Nov 17 '05 #3
Ian Frawley wrote:
I have been thinking about this quite allot and the fact that I am
creating objects on demand within a busy web service could be quite costly
without even using the Activator class. I have started thinking of
possibly pooling a set number of these objects to be used when required
but the thought of locking issues involved and also web clients sitting
about until an object becomes available is another concern. Either way I
think possibly a more elegant solution is called for.

Do you have any articles on caching objects for reuse?


You can find some stuff by googling for "object cache" or "object
pooling", but I don't have anything specific, sorry.

It won't be very difficult to write yourself, though. You need a list of
objects, which may be either taken or not. You need a thread-safe method
that can return an object from the pool. If you want the pool to be sized
dynamically, you need some kind of high- and low-water-mark checking,
either triggered by requests for objects or by timed evaluations of the
fill level of the pool. If you want the pool to instantiate new objects on
demand, you need to have an object factory that the pool can use to do
this. That's it, I think :-) Oh yeah, when you're at it, you might
implement support for Windows performance counters, so you can monitor the
pool performance from the outside :-)

I wonder if something readymade is around somewhere... I might just create
it myself, but not right now. Maybe someone else comes forward with a
suggestion?
Oliver Sturm
--
Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)

Nov 17 '05 #4

"Oliver Sturm" <ol****@sturmne t.org> wrote in message

*snip*

Thanks again

I am going to put some research into object factories I think. I have a low
tech idea that will keep me up and running but what you said below makes
sence. So I think I will belt out my low tech approach and then implement a
pooling system based on an object factory but like I said I will need to do
some reading.

Thanks Oliver

Ian
It won't be very difficult to write yourself, though. You need a list of
objects, which may be either taken or not. You need a thread-safe method
that can return an object from the pool. If you want the pool to be sized
dynamically, you need some kind of high- and low-water-mark checking,
either triggered by requests for objects or by timed evaluations of the
fill level of the pool. If you want the pool to instantiate new objects on
demand, you need to have an object factory that the pool can use to do
this. That's it, I think :-) Oh yeah, when you're at it, you might
implement support for Windows performance counters, so you can monitor the
pool performance from the outside :-)

I wonder if something readymade is around somewhere... I might just create
it myself, but not right now. Maybe someone else comes forward with a
suggestion?
Oliver Sturm
--
Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)

Nov 17 '05 #5
Oliver Sturm <ol****@sturmne t.org> wrote:
I wonder if something readymade is around somewhere... I might just create
it myself, but not right now. Maybe someone else comes forward with a
suggestion?


It sounds like the kind of thing Spring was designed for.

See http://www.springframework.net

I haven't used the .NET version, but I use the Java version all the
time - it's great.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #6
Jon Skeet [C# MVP] wrote:
It sounds like the kind of thing Spring was designed for.

See http://www.springframework.net

I haven't used the .NET version, but I use the Java version all the
time - it's great.


You are right, Spring has the functionality for the object pooling. I
haven't actually used it, but a look at the documentation showed me that
it should do well in this regard. Thanks!
Oliver Sturm
--
Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)

Nov 17 '05 #7
Oliver Sturm wrote:
It sounds like the kind of thing Spring was designed for.

See http://www.springframework.net

I haven't used the .NET version, but I use the Java version all the
time - it's great.


You are right, Spring has the functionality for the object pooling. I
haven't actually used it, but a look at the documentation showed me that
it should do well in this regard. Thanks!


I've had another closer look at Spring.NET and I found that the
functionality is not as complete as I had initially imagined. For the fun
of it, I have now decided to create my own pool implementation as a blog
mini series - find the first part here:

http://www.sturmnet.org/blog/archive...bject-pooling/
Oliver Sturm
--
Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)

Nov 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
12041
by: hazz | last post by:
this is a repost with more concise code (well, for me) and better questions (I hope....) . given the following two classes, my intent is to use either Activator.CreateInstance or InvokeMember pass a token into the instantiated class DBPassword and return a string; ************************************** namespace DBPasswordProvider public class DBPassword {
3
17073
by: System.Reflection Activator | last post by:
************************************** //Load the Assembly Assembly a = Assembly.LoadFrom(sAssembly); //Get Types so we can Identify the Interface. Type mytypes = a.GetTypes(); BindingFlags flags = (BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly); //Iterate through the Assembly to find Class with a Public Interface.
1
11539
by: Johnny R | last post by:
Hello, I'm loading a Class from Assemly DLL using Activator.CreateInstance. That loaded Class is executed in a worker Thread with no loop. What actually happends when class is loaded using Activator.CreateInstance? If I create same class using Activator.CreateInstance many times will there be multiple instances of that same class created by Activator.CreateInstance?
0
1435
by: Jon Skeet [C# MVP] | last post by:
On Apr 11, 8:40 am, Andrew <And...@discussions.microsoft.comwrote: Okay, that means you've either not given the full classname (including namespace) or it's not in mscorlib or the currently executing assembly, in which case you need to give assembly details as well. The line with testType2 is explicitly trying to find a class called "name". The string "name" and the variable called name are completely independent things.
0
9714
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9594
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10351
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9174
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6866
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5534
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4311
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3834
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.