I've been reading a lot about java memory management, garbage collecting et al and I'm trying to find the best settings for my limited memory (1.7g on a small ec2 instance) I'm wondering if there is a direct correlation between my code size and the permgen setting. According to sun:
The permanent generation is special because it holds data needed by the virtual machine to describe objects that do not have an equivalence at the Java language level. For example objects describing classes and methods are stored in the permanent generation.
To me this means that it's literally storing my class def'ns etc... Does this mean there is a direct correlation between my compiled code size and the permgen I should be setting? My whole app is about 40mb and i noticed we're using 256mb permgen. I'm thinking maybe we're using memory that could be better allocated to dynamic code like object instances etc...
Sun says that the permgen is storage for objects that don't have an equivalence in the Java language:
So yeah, the permanent generation contains "internal" JVM data structures that describe objects and methods, among other things. 256 MB might be rather large, but it would depend on the application.
In a large ColdFusion app like I run, a huge amount of classes are created for ColdFusion code that is compiled on-the-fly, and I am running with a permanent generation set to 192 MB. I think I used to run it successfully at 128 MB as well, so it's definitely something you could experiment with.
If you're measuring performance under load before and after you tune these GC parameters, you'll be able to tell what impact your changes have on your application's performance.
Also, the document I linked gives a lot of information about how the JVM manages it's memory- it's quite good reading.
Is your Tomcat configured to automatically redeploy applications that are dropped in the application folder? Do you use that functionality?
If you use that functionality, there's a possibility that the amount of memory used in the PermGen space is gonna increase. This can happen due to (badly written) applications that in some way keep references to the loaded classes alive. Each time there's a redeploy, the amount of memory used in the PermGen space is gonna increase until it overflows.
If you don't use that functionality and always have the same application running on the Tomcat server, then I would just try running Tomcat with the default settings for PermGen space. If the application loads, and runs fine for awhile, then it should be fine. If the application runs out of PermGen space, then just increase it in steps until the PermGen space is big enough.
Why has it been configured to 256m (as seen in your other question) in the first place?
Btw, yes, there is a correlation between the amount of loaded classes and the amount of needed space in the PermGen area. So, yes, the more code that is loaded, the more PermGen space you're gonna need.