Over a million developers have joined DZone.

Does it Help to Move All Jars to a Shared Library?

· Java Zone

Microservices! They are everywhere, or at least, the term is. When should you use a microservice architecture? What factors should be considered when making that decision? Do the benefits outweigh the costs? Why is everyone so excited about them, anyway?  Brought to you in partnership with IBM.

We will be running more than one web application on the same tomcat (7.0.22), so we wondered whether there will be a benefit in moving all jars to tomcat/lib instead of having them in each application’s WEB-INF/lib (since our applications have almost identical dependencies). What this gives as benefit for sure, without even testing, is that the classes are loaded by the parent classloader, and are loaded only once, rather than by each app’s classloader.

Here are the results on my machine, with 2 applications:

Startup times (4 runs):

WEB-INF/lib

INFO: Server startup in 77554 ms
INFO: Server startup in 62391 ms
INFO: Server startup in 62598 ms
INFO: Server startup in 61002 ms

tomcat/lib

INFO: Server startup in 72321 ms
INFO: Server startup in 71151 ms
INFO: Server startup in 69841 ms
INFO: Server startup in 71047 ms

 

Memory (2 runs):

WEB-INF/lib
PermGen: size=278, Used=198
Heap: size=1,029, Used=465

PermGen: Size=276, Used=198
Heap: Size=1,049, USed=501

tomcat/lib
PermGen: Size=199, Used=151
Heap: size=1,043, Used=412

PermGen: Size=195, Used=151
Heap: size=1,035, Used=418

The only difference is in the used PermGen size, which differs with ~50 MB per app (size differs with ~80). (Used Heap goes up and down, hence the difference). This is without working wit the app, which would add a bit more difference, but most of our classes are loaded eagerly by the spring context. So this is not enough benefit for the deployment complications it introduces – you can no longer package your application directly from maven/ant – you have to post-process it to clear the jars, and also make sure your environments have up-to-date tomcat/lib folders.

 

From http://techblog.bozho.net/?p=816

Discover how the Watson team is further developing SDKs in Java, Node.js, Python, iOS, and Android to access these services and make programming easy. Brought to you in partnership with IBM.

Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}