Results 1 to 7 of 7

Thread: Performance Issues on Stress Test Regarding ProxyFactory and NonSingleton Objects

  1. #1
    Join Date
    May 2006
    Posts
    7

    Exclamation Performance Issues on Stress Test Regarding ProxyFactory and NonSingleton Objects

    Im having performance issues when creating ProxyObjects with advices, on performances tests, where i create the same object 1000 times, performance worsens every time the test is run.

    I Know that when not using singleton (i need new instances each time because of object's state) objects it may affect perfomance, but not exponentially as what is happening.

    For example the first time it takes 2 seconds, after that, each new run takes over 2-3 Seconds more than the last test.

    Example:
    Run / Time
    1st / 2 secs
    2nd / 5 secs
    3rd / 7 secs
    4th / 10 secs
    5th / 13 secs

    I tried using Spring Programatically and using configuration, the results are the same.

  2. #2
    Join Date
    May 2006
    Posts
    7

    Default

    This is an example of what i did programatically:

    Code:
    //this is not working code, it just an example
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.Target = targetObject
    proxyFactory.AddAdvice(advice1);
    proxyFactory.AddAdvice(advice2);
    proxyObject = proxyFactory.GetProxy();
    Last edited by jamendoza; 05-31-2006 at 09:40 PM.

  3. #3
    Join Date
    May 2006
    Posts
    7

    Default

    This is what i did on configuration

    Code:
    <!-- this is not working code, it just an example -->
    <object id="advice1" type="....."  singleton="false"/>
    <object id="advice1" type="....."  singleton="false"/>
    <object id="targetObject" type="....." singleton="false"/>
    
    <object id="proxyObject" type="Spring.Aop.Framework.ProxyFactoryObject">
    	<property name="isSingleton" value="false"/>
    	<property name="targetName" value="targetObject" />
    	<property name="interceptorNames">
    		<list>
    			<value>advice1</value>
    			<value>advice2</value>
    		</list>
    	</property>
    </object>
    Last edited by jamendoza; 06-01-2006 at 06:22 PM.

  4. #4
    Join Date
    Oct 2005
    Location
    Toulouse, France
    Posts
    1,407

    Default

    Hi,

    I tried to reproduce it, but everything seems oki here.
    I used the AopQuickStart sample, changed singletons to prototypes and my testing code looks like this :
    Code:
    // Create AOP proxy using Spring.NET IoC container.
    IApplicationContext ctx = ContextRegistry.GetContext();
    
    for (int i = 0; i < 100; i++)
    {
        Stopwatch sw = Stopwatch.StartNew();
        ICommand command = (ICommand)ctx["myServiceObject"];
        command.DoExecute();
        sw.Stop();
        Console.WriteLine(sw.ElapsedMilliseconds);
    }
    what kind of advice are you using ?
    Try to use some basic advices to know if the problem is due to your advices or not.


    -Bruno
    My english is as poor as my taylor is rich

  5. #5
    Join Date
    May 2006
    Posts
    7

    Default

    Hi, i did an example solution to prove what im talking about,
    the link to the solution is at the end of this post, unfortunately, due to size limits, i had to exclude spring's dlls so, just open the solution and re-add the references.

    I did 3 runs

    1.- Open app, and execute programatic creation 5 times, close app


    2.- Open app, and execute creation with applicationcontext 5 times, close app


    3.- 1.- Open app, and execute 3 programatic and 2 with applicationcontext, close app
    http://forum.springframework.net/att...1&d=1149204470

    The targetObject is a simple class with 2 fields (1 is string, the other is an int)

    Here is an extraction from the code that creates programatically:
    Code:
    for(int i = 0; i<1000; i++)
    {
    	targetObject = new TargetObject();
    	sampleAfterAdvice = new SampleAfterAdvice();
    	sampleBeforeAdvice = new SampleBeforeAdvice();
    	proxyFactory = new ProxyFactory(targetObject);
    	proxyFactory.AddAdvice(sampleAfterAdvice);
    	proxyFactory.AddAdvice(sampleBeforeAdvice);
    	targetObject = (ITargetObject)proxyFactory.GetProxy();
    }
    Here is an extraction from the code that uses applicationcontext:
    Code:
    for(int i = 0; i<1000; i++)
    {
    	targetObject = (ITargetObject) applicationContext.GetObject("ProxyObject");
    }
    Here is the object configuration
    Code:
    <objects xmlns="http://www.springframework.net">
    	<object id="SampleAfterAdvice"  
    			type="SpringSample.SampleAfterAdvice, SpringSample"  singleton="false"/>
    	<object id="SampleBeforeAdvice" 
    			type="SpringSample.SampleBeforeAdvice, SpringSample" singleton="false"/>
    	<object id="TargetObject" 
    			type="SpringSample.TargetObject, SpringSample"		 singleton="false"/>
    
    	<object id="ProxyObject" type="Spring.Aop.Framework.ProxyFactoryObject">
    		<property name="isSingleton" value="false"/>
    		<property name="targetName"  value="TargetObject" />
    		<property name="interceptorNames">
    			<list>
    				<value>SampleAfterAdvice</value>
    				<value>SampleBeforeAdvice</value>
    			</list>
    		</property>
    	</object>
    </objects>
    And here are the main methods of the Before and After Advices

    Code:
    public void AfterReturning
    	(object returnValue, MethodInfo method, object[] args, object target)
    {
    	//I commented this line so it wont interfere with this test, 
    	//but it can be uncommented to show the advices actually works
    	//Console.WriteLine("I'm the after advice");
    }
    Code:
    public void Before
    	(MethodInfo method, object[] args, object target)
    {
    	//I commented this line so it wont interfere with this test, 
    	//but it can be uncommented to show the advices actually works
    	//Console.WriteLine("I'm the before advice");
    }
    Download the Solution (zip file)
    Attached Images Attached Images
    Attached Files Attached Files

  6. #6
    Join Date
    Oct 2005
    Location
    Toulouse, France
    Posts
    1,407

    Default

    Hi,

    Problem here is that the Proxy is created each time and maybe you don't need it.
    Why not using a PrototypeTargetSource in your ProxyFactory if your target is a prototype (By default, it uses a SingletonTargetSource) :
    Code:
    <object id="ProxyObject" type="Spring.Aop.Framework.ProxyFactoryObject">
      <property name="targetSource">
        <object type="Spring.Aop.Target.PrototypeTargetSource, Spring.Aop">
          <property name="TargetObjectName" value="TargetObject" />
        </object>
      </property>
      <property name="interceptorNames">
        <list>
          <value>SampleAfterAdvice</value>
          <value>SampleBeforeAdvice</value>
        </list>
      </property>
    </object>
    Or do you really need a new proxy for each call ?

    Take a look to the documentation :

    Quote Originally Posted by Reference documentation
    IsSingleton whether or not the factory should return a single proxy object, no matter how often the GetObject() method is called. Several IFactoryObject implementations offer such a method. Default value is true. If you would like to be able to apply advice on a per-proxy object basis, use a IsSingleton value of false and a IsFrozen value of false. If you want to use stateful advice--for example, for stateful mixins--use prototype advices along with a IsSingleton value of false.
    ProxyFactoryObject Properties

    Prototype target sources


    Cheers,
    Bruno Baia
    Last edited by Bruno Baia; 06-02-2006 at 09:37 AM.
    My english is as poor as my taylor is rich

  7. #7
    Join Date
    May 2006
    Posts
    7

    Thumbs up

    Thanks a lot Bruno!!, that solved my configuration test, but, what about if i want to do it programatically?? How can i accomplish the same result without the overhead ??
    Last edited by jamendoza; 06-02-2006 at 02:27 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •