Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pros and Cons of using shared library vs fully encapsulated EAR

Our team builds and owns a webservices framework. Other teams which actually build the webservices use our framework for some common functionality. There are two options to package the EAR. Option 1 is to have all the framework jars built into the EAR. Option 2 is to configure a shared library in the application server and make all applications use the library. We have potential of upto 100 EARS being deployed, that will use this framework. What are some pros and cons off this approach in terms of build,manageability and development. We are using websphere.

like image 454
zkarthik Avatar asked Jul 04 '09 11:07

zkarthik


People also ask

What are the benefits of shared libraries?

The advantages of shared libraries are: Less disk space is used because the shared library code is not included in the executable programs. Less memory is used because the shared library code is only loaded once. Load time may be reduced because the shared library code may already be in memory.

Should I use static or shared library?

Static libraries take longer to execute, because loading into the memory happens every time while executing. While Shared libraries are faster because shared library code is already in the memory. In Static library no compatibility issue has been observed.

Why shared libraries are preferred over static libraries?

The most significant advantage of shared libraries is that there is only one copy of code loaded in memory, no matter how many processes are using the library. For static libraries each process gets its own copy of the code. This can lead to significant memory wastage.


2 Answers

The basic tradeoff is memory consumption versus version management.

If you package libraries in an EAR, then each application will create its own class instances, consuming some amount of permgen (or equivalent) as well as taking up heap space for static data.

If you store a library in the application lib directory, then there will only be one instance of each class. However, it means that each of the applications using that library must use the same version, and (unless backwards compatibility is ensured) must upgrade at the same time.

Given that you're talking about 100 EARs, the version management issue is probably going to be big. Unless your library as absolutely huge (and I'm going to assume that you're running on a 64 bit server with lots of memory, so make that HUGE), or is never going to change (unlikely), I'd suggest packaging with the EAR.

like image 133
kdgregory Avatar answered Nov 15 '22 11:11

kdgregory


Another thing to note is that if you want to share object instances between EARs, e.g. using the websphere dynacache, the classes for those objects will need to be loaded from shared libraries. (otherwise, even though they may be the same class/version, they will be loaded by different classloaders and not compatible)

I usually go with the plain-vanilla "package everything in EAR" approach as well, but then make exceptions for stuff that needs to be shared, and put those classes into a special shared JAR.

like image 40
Michael Lucas Avatar answered Nov 15 '22 10:11

Michael Lucas