Tag Archives: garbage collection

Apache Serving Blank Screen – even in CF Admin

Apache has started doing this; a blank screen. A restart of tomcat seems to fix it, but this cannot be the answer, especially when it’s only just started, AND it’s not like it is poor code; the error occurs even in ColdFusion administrator.

apache timeout.PNG

A quick check in the Apache logs (C:\Program Files\Apache Software Foundation\Tomcat 6.0\logs) shows the following error:

Mar 27, 2014 9:40:47 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet CfmServlet threw exception
     java.lang.OutOfMemoryError: PermGen space
          at java.lang.Throwable.printStackTrace(Throwable.java:643)
          at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:100)
          at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
          at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
          at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46)
          at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)

This is either caused by a memory leak, or the PermGen space is just too small for what I genuinely need. I’m thinking that it might just be too small for the size of application I am running, as it is quite a large application, and the last time this happened, it was on the first deploy of another large application (albeit both times I was in CF Admin to configure the setup). So, it could be a memory leak in CF Admin (which I doubt), a memory leak in the application CF (very possible if someone has been sloppy with “var scoping”), or a larger PermGen space needed (possible from deploying a large application).

Forcing Garbage Cleanup

To check if the problem was memory related inside Tomcat (which looks likely), I first enabled “Class Unloading” inside Tomcat, so that unused classes were free to delete in memory. This isn’t an ideal or long term solution however; for one thing, it increases processing time as classes have to be recreated as they are called, but this is a useful test nonetheless – especially when exploring an application for a memory leak:

  1. Open “Tomcat Properties”: Open C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Apache Tomcat 6.0 Tomcat6/ “Configure Tomcat”. This runs Tomcat6w.exe with additional arguments.

  2. Stop Tomcat: Click on the “General” tab, click on “Stop”. Check the task manager for when the service has stopped. This can take a while sometimes, as much as 15 minutes waiting for the service to stop. If Tomcat hangs with “Stopping” status, read this post to kill it.

  3. Update Java Options: Click on the “Java” tab, and add the following arguments to the bottom of the Java Options box:
    -XX:+CMSClassUnloadingEnabled
    -XX:+CMSPermGenSweepingEnabled
    Apache Java Memory Cleanup

  4. Restart Tomcat

This worked for me, both the application and ColdFusion Administrator are running well now – proving that the problem is a memory issue (no surprise there really).

Using Memory Limits

I could leave the server running as is, but class unloading slows down an application, and it won’t tell me if there’s a memory leak in the application. If there IS a memory leak, this would eventually manifest itself on the production server too – so I would rather know about a memory leak now, than later. Think of it like a car that is running rich, and burning to much fuel; putting in more fuel keeps the car running, but this does not fix the problem, only hides it. The car is using far more fuel than it should, and eventually we will run out of money to fuel the car – so its best to fix the engine.

To use the memory limits (either increasing or decreasing), follow these steps:

  1. Open “Tomcat Properties”: Open C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Apache Tomcat 6.0 Tomcat6/ “Configure Tomcat”. This runs Tomcat6w.exe with additional arguments.
  2. Stop Tomcat: Click on the “General” tab, click on “Stop”. Check the task manager for when the service has stopped. This can take a while sometimes, as much as 15 minutes waiting for the service to stop. If Tomcat hangs with “Stopping” status, read this post to kill it.

  3. Update Java Options: Click on the “Java” tab, remove the arguments added for garbage cleanup, and add the following arguments to the bottom of the Java Options box:
    -XX:MaxPermSize=128m” (set the 128 to whatever you want)

  4. Restart the Server

It’s working for me, for now at least – but if ColdFusion Admin or my application breaks down again, then it is possible that there is a memory leak somewhere. I could increase the memory again further (if it is genuinely needed) but I would need justification to think that it needs the extra memory. To be honest, I would probably check for issues in the code before I increased the memory again.