CreateInstranceAndUnwrap slow perfomance

Discussion in 'ASP .Net' started by Gnanaprakash Rathinam, Dec 29, 2004.

  1. Hi Expert,

    We are trying to create an object in secondary appdomain from default
    appdomain using CreateInstanceAndUnwrap api, But this call seems to be
    taking lot of time to return, I know the call involve loading of required
    assembly of the class/type and create object of type and return the proxy
    object to the default domain. But I look for any other alternative way of
    doing this???


    // Sample c# code
    class Test
    {

    static void Main()
    {
    CreateInstanceInSecondaryAppdomain(); // OK!
    }

    static void CreateInstanceInSecondaryAppdomain()
    {
    try
    {

    // Create a new AppDomain.
    AppDomain ad =
    AppDomain.CreateDomain("SecondaryAppDomain");


    MarshalByRefType instance = (MarshalByRefType)
    ad.CreateInstanceAndUnwrap(
    Assembly.GetCallingAssembly().FullName,
    "CreateInstanceAndUnWrap.MarshalByRefType",
    true,
    BindingFlags.Default,
    null,
    null,
    null,
    null,
    null
    );

    // I'm done using the other AppDomain, so
    // I'll unload it and all its assemblies.
    AppDomain.Unload(ad);
    }
    catch (TypeLoadException e)
    {
    Console.WriteLine(e.Message);
    }
    }
    }

    class MarshalByRefType : MarshalByRefObject
    {
    //System.Runtime.Remoting.Activation.IActivator.
    // This instance method can be called via a proxy.

    public MarshalByRefType()
    {
    }
    public void SomeMethod(String sourceAppDomain)
    {
    // Display the name of the calling AppDomain and my AppDomain.
    // NOTE: The application's thread has transitioned between
    AppDomains.
    Console.WriteLine(
    "Code from the '{0}' AppDomain\n" +
    "called into the '{1}' AppDomain.",
    sourceAppDomain,
    Thread.GetDomain().FriendlyName);
    }
    }

    Thanks,
    GP.
     
    Gnanaprakash Rathinam, Dec 29, 2004
    #1
    1. Advertising

  2. Gnanaprakash Rathinam

    Mujtaba Syed Guest

    Hi:

    > We are trying to create an object in secondary appdomain from default
    > appdomain using CreateInstanceAndUnwrap api, But this call seems to be
    > taking lot of time to return, I know the call involve loading of required


    How much time?
    You are using late binding and that too across AppDomains. It's definitely
    not going to be as fast as a new ().

    Mujtaba.
     
    Mujtaba Syed, Dec 29, 2004
    #2
    1. Advertising

  3. It is somewhere around 15-20 milliseconds on uniprocessor pentium 2.6GHz
    with 1GB RAM

    "Mujtaba Syed" <> wrote in message
    news:...
    > Hi:
    >
    > > We are trying to create an object in secondary appdomain from default
    > > appdomain using CreateInstanceAndUnwrap api, But this call seems to be
    > > taking lot of time to return, I know the call involve loading of

    required
    >
    > How much time?
    > You are using late binding and that too across AppDomains. It's definitely
    > not going to be as fast as a new ().
    >
    > Mujtaba.
    >
    >
    >
    >
    >
     
    Gnanaprakash Rathinam, Dec 30, 2004
    #3
  4. Gnanaprakash Rathinam

    David Levine Guest

    Does it take that long each time you call CreateInstanceAndUnwrap or only
    the 1st time you call it? It is a fairly heavy operation to create and
    destroy an appdomain. When you destroy the appdomain all objects that are
    rooted in it are garbage collected, and all finalizers of those objects run
    to completion before the destroy call completes - this is time consuming.

    Try running another timing test but don't include the appdomain
    create/destroy in the test.

    "Gnanaprakash Rathinam" <> wrote in message
    news:8jLAd.32$...
    > It is somewhere around 15-20 milliseconds on uniprocessor pentium 2.6GHz
    > with 1GB RAM
    >
    > "Mujtaba Syed" <> wrote in message
    > news:...
    >> Hi:
    >>
    >> > We are trying to create an object in secondary appdomain from default
    >> > appdomain using CreateInstanceAndUnwrap api, But this call seems to be
    >> > taking lot of time to return, I know the call involve loading of

    > required
    >>
    >> How much time?
    >> You are using late binding and that too across AppDomains. It's
    >> definitely
    >> not going to be as fast as a new ().
    >>
    >> Mujtaba.
    >>
    >>
    >>
    >>
    >>

    >
    >
     
    David Levine, Dec 30, 2004
    #4
  5. The timing include only the call to CreateInstanceAndUnwrap, but the second
    call to CreateInstanceAndUnwrap takes very less time, close to 1
    millisecond, so for first call this long time (~15ms) is required to load an
    assembly into appdomain?

    "David Levine" <> wrote in message
    news:#...
    > Does it take that long each time you call CreateInstanceAndUnwrap or only
    > the 1st time you call it? It is a fairly heavy operation to create and
    > destroy an appdomain. When you destroy the appdomain all objects that are
    > rooted in it are garbage collected, and all finalizers of those objects

    run
    > to completion before the destroy call completes - this is time consuming.
    >
    > Try running another timing test but don't include the appdomain
    > create/destroy in the test.
    >
    > "Gnanaprakash Rathinam" <> wrote in

    message
    > news:8jLAd.32$...
    > > It is somewhere around 15-20 milliseconds on uniprocessor pentium 2.6GHz
    > > with 1GB RAM
    > >
    > > "Mujtaba Syed" <> wrote in message
    > > news:...
    > >> Hi:
    > >>
    > >> > We are trying to create an object in secondary appdomain from default
    > >> > appdomain using CreateInstanceAndUnwrap api, But this call seems to

    be
    > >> > taking lot of time to return, I know the call involve loading of

    > > required
    > >>
    > >> How much time?
    > >> You are using late binding and that too across AppDomains. It's
    > >> definitely
    > >> not going to be as fast as a new ().
    > >>
    > >> Mujtaba.
    > >>
    > >>
    > >>
    > >>
    > >>

    > >
    > >

    >
    >
     
    Gnanaprakash Rathinam, Dec 30, 2004
    #5
  6. Gnanaprakash Rathinam

    David Levine Guest

    "Gnanaprakash Rathinam" <> wrote in message
    news:B_SAd.20$...
    > The timing include only the call to CreateInstanceAndUnwrap, but the
    > second
    > call to CreateInstanceAndUnwrap takes very less time, close to 1
    > millisecond, so for first call this long time (~15ms) is required to load
    > an
    > assembly into appdomain?
    >


    That's probably the case. Loading an assembly is considered to be a "heavy"
    operation, since it is a container for types, acts as a security boundary,
    etc. There's a lot of overhead in loading the assembly, but once it is
    loaded the results are cached.
     
    David Levine, Dec 30, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fredrik Melin

    Server perfomance

    Fredrik Melin, Oct 27, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    417
    Paul Glavich [MVP - ASP.NET]
    Oct 27, 2004
  2. Scott Reynolds

    data perfomance?

    Scott Reynolds, Mar 1, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    431
    Karl Seguin
    Mar 1, 2005
  3. George

    Huge HTML output perfomance

    George, Mar 28, 2005, in forum: ASP .Net
    Replies:
    10
    Views:
    680
    Robbe Morris [C# MVP]
    Mar 29, 2005
  4. James T.

    Perfomance test

    James T., Feb 26, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    412
    James T.
    Feb 26, 2006
  5. iksrazal
    Replies:
    2
    Views:
    358
    enrique
    Apr 27, 2005
Loading...

Share This Page