AOP Benchmark

The need for performance metrics and comparison

Since we released AspectWerkz 1.0, and more generally for every release of any AOP / interceptor framework (AspectWerkz, AspectJ, JBoss AOP, Spring AOP, cglib, dynaop etc), a question is always raised: "what is the performance cost of such an approach?", "how much do I loose per method invocation when an advice / interceptor is applied?".

This is indeed an issue that needs to be carefully addressed, and that in fact has affected the design of every mature enough framework.

We are probably all scared by the cost of the java.lang.reflect despite its relative power, and usually, even before starting to evaluate semantics robustness and ease of use in general - we start doing some Hello World bench.

We have started AWbench for that purpose. Offering a single place to measure the relative performance of AOP/Interceptor frameworks, and measure it by your own.

More than providing performance comparison, AWbench is a good place to figure out the semantic differences and ease of use of each framework by using them for the same rather simple purpose. A "line of count" metrics will be provided in a next report.

Current performance results

This table provides the figures from a bench in "nanosecond per advised method invocation". A single method invocation is roughly about 5 ns/iteration on the bench hardware/software that was used. Note that an advised application will have more behavior than just a non advised method so you should not compare non advised version to advised version. AWbench does not provide yet metrics for a hand written implementation of the AOP concepts.

The results were obtained with 2 million iterations.

In this table, the two first lines in bold are the most important ones. In a real world application, it is likely that the before or around advice will interact with the code it is advising and to be able to do that it needs to access runtime information (contextual information) like method parameters values and target instance. It is also likely that the join point is advised by more than one advice.

On the opposite it is very unlikely to have just a before advice that does nothing, but it gives us a good evaluation on the most minimal overhead we can expect.

Note: comparing such results when the difference is small (f.e. 15 ns vs 10 ns) might not be relevant. Before doing so you should run the bench several time and compute an average after removing the smallest and highest measurements.

AWBench (ns/invocation)aspectwerkzawproxyaspectwerkz_1_0aspectjjbossspringdynaopcglibext:aopallianceext:springext:aspectj
before, args() target()102560610220355390145-220-
around x 2, args() target()808565150290436455155465476-
before15205201514527532070-4010
before, static info access30305012517527533070-35-
before, rtti info access50555355017527533575-35-
after returning10205411013528531585-4515
after throwing35403870610330095032-67098127--3460
before + after20305112016044534580-3520
before, args() primitives102055510195350375145-210-
before, args() objects52554610185325345115-200-
around609547010-22531575--90
around, rtti info access707052050140250340807070-
around, static info access809048625135245330758080-


This table provides the figures from the same bench where for each category AspectWerkz 2.0.RC2-snapshot is the reference.
The first line illustrates that for the most simple before advice, AspectWerkz is 13 times faster than JBoss AOP 1.0.

AWBench (relative %)aspectwerkzawproxyaspectwerkz_1_0aspectjjbossspringdynaopcglibext:aopallianceext:springext:aspectj
before, args() target()1 x2.5 x60.6 x1 x22 x35.5 x39 x14.5 x-22 x-
around x 2, args() target()1 x1 x8.1 x0.6 x3.6 x5.4 x5.6 x1.9 x5.8 x5.9 x-
before1 x1.3 x34.6 x1 x9.6 x18.3 x21.3 x4.6 x-2.6 x0.6 x
before, static info access1 x1 x16.7 x0.8 x5.8 x9.1 x11 x2.3 x-1.1 x-
before, rtti info access1 x1.1 x10.7 x1 x3.5 x5.5 x6.7 x1.5 x-0.7 x-
after returning1 x2 x54.1 x1 x13.5 x28.5 x31.5 x8.5 x-4.5 x1.5 x
after throwing1 x1 x1.7 x0.8 x1.4 x-1.8 x2.2 x--0.9 x
before + after1 x1.5 x25.5 x1 x8 x22.2 x17.2 x4 x-1.7 x1 x
before, args() primitives1 x2 x55.5 x1 x19.5 x35 x37.5 x14.5 x-21 x-
before, args() objects1 x5 x109.2 x2 x37 x65 x69 x23 x-40 x-
around1 x1.5 x7.8 x0.1 x-3.7 x5.2 x1.2 x--1.5 x
around, rtti info access1 x1 x7.4 x0.7 x2 x3.5 x4.8 x1.1 x1 x1 x-
around, static info access1 x1.1 x6 x0.3 x1.6 x3 x4.1 x0.9 x1 x1 x-

Bench were run on a Java HotSpot 1.4.2, Windows 2000 SP4, Pentium M 1.6 GHz, 1 Go RAM.

Notes:

  • Some figures are not available when the underlying framework does not allow the feature. For the ext: ones, that can be due to pending work (AOP alliance interfaces can emulate a before advice just as it is the case in JBoss AOP).
  • after throwing advice appears to be slow since it first, is an overhead in throwing the exception (user code) and second, in catching the exception and do an instanceof to check the exception type (advice code).
  • latest run: Dec 20, 2004, as per Spring Framework team feedback.

AWbench internals

Summary

AWbench is a micro benchmark suite, which aims at staying simple. The test application is very simple, and AWbench is mainly the glue around the test application that applies one or more very simple advice / interceptor of the framework of your choice.

AWbench comes with an Ant script that allows you to run it on you own box, and provide some improvement if you know some for a particular framework.

What is the scope for the benchmark?

So far, AWbench includes method execution pointcuts, since call side pointcuts are not supported by proxy based framework (Spring AOP, cglib, dynaop etc).

The awbench.method.Execution class is the test application, and contains one method per construct to bench. An important fact is that bytecode based AOP may provide much better performance for before advice and after advice, as well as much better performance when it comes to accessing contextual information.
Indeed, proxy based frameworks are very likely to use reflection to give the user access to intercepted method parameters at runtime from within an advice, while bytecode based AOP may use more advanced constructs to provide access at the speed of a statically compiled access.

The current scope is thus:

For method execution pointcut

Construct Contextual information access Notes
   
before advice none  
before advice static information (method signature etc)  
before advice contextual information accessed reflectively Likely to use of casting and unboxing of primitives
before advice contextual information accessed with explicit framework capabilities Only supported by AspectJ and AspectWerkz 2.x
   
after advice none  
after returning advice return value  
after throwing advice exception instance  
   
before + after advice none  
   
around advice optimized AspectJ and AspetWerkz 2.x provides specific optimizations (thisJoinPointStaticPart vs thisJoinPoint)
around advice non optimizezd  
   
2 around advice contextual information  

By accessing contextual information we means:

  • accessing a method parameter using its real type (i.e. boxing and unboxing might be needed)
  • accessing a the advised instance using its real type (i.e. casting might be needed)

A pseudo code block is thus likely to be:

class awbench.method.Execution {

  int m_field;

  void before(int i) {
    // very simple test application method body - does not vary
    m_field++;
  }
}

class XXframework {

  // might be optimized by some framework using lazy instantiation
  .. interceptWithoutContextualInformationAccess(..) {
    // very simple advice body - does not vary
    awbench.Run.staticIntField++;
  }

  .. interceptWithReflectiveContextualInformationAccess(.., XXInvocation invocation, ..) {
    // very simple advice body - does not vary
    awbench.Run.staticIntField++;
    // reflective access to target instance and intercepted method argument
    Execution target = (Execution) invocation.getTarget();
    int arg0 = (int) (Integer(invocation.getArgument_0())).intValue();
  }

  // may not be supported by all framework
  .. interceptWithDirectContextualInformationAccess(.., Execution executionTargetInstance, int arg0Intercepted, ..) {
    // very simple advice body - does not vary
    awbench.Run.staticIntField++;
    // direct access to target instance and intercepted method argument thru rich framework facilities
    Execution target = executionTargetInstance; // no casting
    int arg0 = arg0Intercepted; // no casting
  }
}
Which AOP and Proxy frameworks are benched?

The following are included in AWbench:

Bytecode based frameworks

Framework URL
AspectWerkz 1.0 http://aspectwerkz.codehaus.org
AspectWerkz 2.x http://aspectwerkz.codehaus.org
AspectJ (1.2) http://eclipse.org/aspectj/
JBoss AOP (1.0) http://www.jboss.org/developers/projects/jboss/aop

Proxy based frameworks

Framework URL
Spring AOP (1.1.1) http://www.springframework.org/
cglib proxy (2.0.2) http://cglib.sourceforge.net/
dynaop (1.0 beta) https://dynaop.dev.java.net/

Moreover, AWbench includes AspectWerkz Extensible Aspect Container that allow to run any Aspect / Interceptor framework within the AspectWerkz 2.x runtime:

AspectWerkz Extensible Aspect Container running Notes
AspectJ  
AOP Alliance http://aopalliance.sourceforge.net/
Spring AOP  

AWbench is extensible. Refer to the How to contribute? section (below) for more info on how to add your framework to the bench.

What's next ?

Running awbench by your own

AWBench is released under LGPL.
There will never be a distribution of it, but source can be checked out:

cvs -d :pserver:anonymous@cvs.aspectwerkz.codehaus.org:/home/projects/aspectwerkz/scm login

cvs -z3 -d :pserver:anonymous@cvs.aspectwerkz.codehaus.org:/home/projects/aspectwerkz/scm co awbench

Once checked out, you can run the bench using several different Ant target

ant run

ant run:aspectwerkz
ant run:aspectj
ant run:jboss

ant run:ext:aspectj
ant run:ext:spring
ant run:ext:aopalliance

ant run:cglib
ant run:spring
ant run:dynaop

ant run:all
How to contribute?

If you notice some optimizations for one of the implementation by respecting the requirements, we will add the fix in awbench and update the results accordingly.

If you are willing to write a non-AOP, non-Proxy based version of this bench so that a comparison between AOP approach and regular OO design patterns is possible send us an email.

Limitations

The current implementation is not covering fine grained deployment models like perInstance / perTarget, whose underlying implementation are unlikely to be neutral on performance results.

From:http://docs.codehaus.org/display/AW/AOP+Benchmark

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值