The method being invoked is:
public long add(long arg0, long arg1);
Each run invokes the method 50,000,000 times. The elapsed time is the time in milliseconds. Note that the Java clock (System.currentTimeMillis()
) is very, very innaccurate.
JDK 1.4, Windows XP, Hotspot Server
Run | Bean | Interface | Singleton | Deferred | Threaded |
---|---|---|---|---|---|
Run #1 | 200 | 320 | 2003 | 2544 | 2874 |
Run #2 | 220 | 2324 | 2223 | 2614 | 2844 |
Run #3 | 210 | 2454 | 2894 | 2654 | 2894 |
Run #4 | 210 | 2223 | 2083 | 2604 | 2734 |
Run #5 | 230 | 2083 | 2073 | 2594 | 2794 |
Bean - invoking the method directly on the service implementation class (that is, instantiate the class without using HiveMind)
Interface - Invoking the method against an interface, not object, reference
Singleton - Invoking the method against the service using the singleton model (as expected, very close performance to interface)
Deferred - Invoking the method against the service using the deferred model (slight increase in time reflects the extra proxy and synchronized block)
Threaded - Invoking the method against the service using the threaded model (another increase for the additional proxy and the ThreadLocal stuff)
JDK 1.4, Windows XP, Hotspot Client
Run | Bean | Interface | Singleton | Deferred | Threaded |
---|---|---|---|---|---|
Run #1 | 381 | 2183 | 2193 | 5157 | 8573 |
Run #2 | 380 | 2203 | 2213 | 4116 | 7701 |
Run #3 | 371 | 2203 | 2243 | 4186 | 7681 |
Run #4 | 371 | 2203 | 2253 | 4126 | 7701 |
Run #5 | 371 | 2203 | 2213 | 4126 | 7701 |
Big difference switching from Hotspot server to Hotspot client; hard to say why in particular ... less inlining but also less of a difference between bean and interface, but the additional cost of the extra proxies (for deferred and threaded) and for the ThreadLocal stuff (for the threaded model).
Something useful to do next would be to create a more realistic bean, something less likely to be completely inlined by HotSpot, so we can really see the difference between the Bean and Interface invocation costs. I think the take away is that the big cost is the difference between Bean and Interface, the cost of adding Deferred or Threaded service model is costly, but incremental.
In addition, the little bit of performance testing I've done using the HiveMind test suite shows that the one-time cost of parsing the HiveMind module deployment descriptors is signifcant; all else is dwarfed by this cost. I'm concerned, or perhaps merely curious, about performance when you build a full application from a wide mix of singleton, deferred and threaded services. Services calling services calling services, all as interfaces, all with proxies and perhaps interceptors ... what will be the cost of all that wrapper code? On the other hand, what are the costs of executing a managed object as an EJB? I'm fairly confident that refactoring stateless session EJBs into HiveMind services (deferred or threaded) would be a net win performance-wise.
No comments:
Post a Comment