Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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...

share|improve this question

2 Answers 2

up vote 1 down vote accepted

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.

share|improve this answer
    
256 is what it was configured at before I came in so I'm not sure why it was chosen. We actually stop tomcat and restart on each deploy and it only runs one app so I don't think we'd have that problem of it keeping old apps in memory. In the logs I've never seen it go above 50mb so I've set it to 80mb just to give a bit of a buffer. –  brad Mar 16 '10 at 16:35

Sun says that the permgen is storage for objects that don't have an equivalence in the Java language:

A third generation closely related to the tenured generation is the permanent generation. 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.

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.

share|improve this answer
    
ya that's where i got my quote also. I just wasn't sure if there's extra stuff going in that perm gen aside from my own code. I literally have 45mb of compiled code. And the GC logs show permgen usually hovers around 50mb –  brad Mar 10 '10 at 17:00
    
Shrink it, then. Why not? Try 128 MB and let it run for a while. –  Clint Miller Mar 11 '10 at 22:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.