Just in time for Christmas, there are Good Tidings - Weld has improved a lot, and I can no longer see any suspicious memory usage related to Weld. I took my Wicket+EJB+OpenJPA+PostgreSQL application packaged in a single WAR and deployed it to several different Glassfish versions from the command line. Then I used the Eclipse Memory Analyzer to a create a heap dump of the running Glassfish instance.
The Total Heap column in the following table is the total size of the heap as reported by the Memory Analyzer. The Shallow, Retained, and Percentage Columns refer to the amount of heap memory consumed by instances of
|Glassfish Version||Total Heap||Shallow||Retained||Percentage|
|3.0.1||412.1 MB||84.680||378.215.056||87.52 %|
|3.1-b26||335.3 MB||85.144||205.527.048||58.38 %|
|3.1-b33||149.6 MB||84.216||7.041.704||4.49 %|
The retained heap of an object is the set of objects that will be garbage collected when the given parent object is garbage collected.
So in b33, Weld still holds 5 % of the total heap - whether or not this is still too much or just reasonable is surely debatable. But I'm really happy to see that Weld has improved a lot, so I would no longer consider it as a no-go.
The version of my application I used for these measurements is the last one that actually used Weld, before I decided in August to stop using CDI to get rid of most memory issues.
I took some more measurements with the successor version in which CDI was eliminated essentially just by replacing @Inject by @EJB throughout the sources. This is really the only difference between the two versions, and here are the total heap sizes:
|Glassfish Version||with @Inject||with @EJB|
|3.0.1||412.1 MB||44.4 MB|
|3.1-b33||149.6 MB||138.3 MB|
The illustrates, as claimed in my previous post, that I was able to save 90 % of heap memory by not using CDI on Glassfish 3.0.1. Doing the same on Glassfish 3.1-b33, I can still save about 9 %.
But I was really surprised to see the heap usage of my application increase by a factor of 3 between Glassfish 3.0.1 and 3.1-b33.
The Memory Analyzer reveals the culprit to be
org.glassfish.hk2.classmodel.reflect.impl.TypesCtrwith a retained heap of about 80 MB.
I have no clue what this class is doing, but it smells like another case of an oversized reflective model of the application, which was just the problem with earlier Weld versions.
GLASSFISH-15266 is the related issue in Glassfish JIRA.