Image processing - Out of memory

Our environment is set up with 1GB heap and we get OOM after a short period:

2015-08-14 14:46:33,766 ERROR c.e.x.p.i.e.PortalExceptionMapper - Java heap space
java.lang.OutOfMemoryError: Java heap space
        at java.awt.image.DataBufferByte.<init>(DataBufferByte.java:92) ~[na:1.8.0_40]
        at java.awt.image.ComponentSampleModel.createDataBuffer(ComponentSampleModel.java:445) ~[na:1.8.0_40]
        at java.awt.image.Raster.createWritableRaster(Raster.java:941) ~[na:1.8.0_40]
        at javax.imageio.ImageTypeSpecifier.createBufferedImage(ImageTypeSpecifier.java:1074) ~[na:1.8.0_40]
        at javax.imageio.ImageReader.getDestination(ImageReader.java:2892) ~[na:1.8.0_40]
        at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:1071) ~[na:1.8.0_40]
        at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:1039) ~[na:1.8.0_40]
        at javax.imageio.ImageIO.read(ImageIO.java:1448) ~[na:1.8.0_40]
        at javax.imageio.ImageIO.read(ImageIO.java:1352) ~[na:1.8.0_40]
        at com.enonic.xp.portal.impl.resource.image.ImageHandleResource.toBufferedImage(ImageHandleResource.java:80) ~[na:na]
        at com.enonic.xp.portal.impl.resource.image.ImageHandleResource.handle(ImageHandleResource.java:47) ~[na:na]
        at sun.reflect.GeneratedMethodAccessor30.invoke(Unknown Source) ~[na:na]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_40]
        at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_40]
        at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:137) ~[na:na]
        at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:296) ~[na:na]
        at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:250) ~[na:na]
        at org.jboss.resteasy.core.ResourceLocatorInvoker.invokeOnTargetObject(ResourceLocatorInvoker.java:140) ~[na:na]
        at org.jboss.resteasy.core.ResourceLocatorInvoker.invoke(ResourceLocatorInvoker.java:109) ~[na:na]
        at org.jboss.resteasy.core.ResourceLocatorInvoker.invokeOnTargetObject(ResourceLocatorInvoker.java:135) ~[na:na]
        at org.jboss.resteasy.core.ResourceLocatorInvoker.invoke(ResourceLocatorInvoker.java:109) ~[na:na]
        at org.jboss.resteasy.core.ResourceLocatorInvoker.invokeOnTargetObject(ResourceLocatorInvoker.java:135) ~[na:na]
        at org.jboss.resteasy.core.ResourceLocatorInvoker.invoke(ResourceLocatorInvoker.java:109) ~[na:na]
        at org.jboss.resteasy.core.ResourceLocatorInvoker.invokeOnTargetObject(ResourceLocatorInvoker.java:135) ~[na:na]
        at org.jboss.resteasy.core.ResourceLocatorInvoker.invoke(ResourceLocatorInvoker.java:103) ~[na:na]
        at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356) ~[na:na]
        at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179) ~[na:na]
        at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220) ~[na:na]
        at com.enonic.xp.web.jaxrs.JaxRsHandler.doHandle(JaxRsHandler.java:48) ~[na:na]
        at com.enonic.xp.web.handler.BaseWebHandler.handle(BaseWebHandler.java:40) ~[web-api-5.1.0.jar:5.1.0]
        at com.enonic.xp.web.impl.WebHandlerChainImpl.handle(WebHandlerChainImpl.java:35) ~[web-impl-5.1.0.jar:5.1.0]
        at com.enonic.xp.web.handler.BaseWebHandler.handle(BaseWebHandler.java:36) ~[web-api-5.1.0.jar:5.1.0]

This site is very simple, but the content managers uploads very large images as content. I suppose this is due to the fact that images are not cached and hence the scaling has to be done on every requests.

Are you aware of this ?

  • Petter -

What do you mean “very large image”? Regular photographs from 12 mega pixels and upwards?

In general, 1Gb is quite small for an Enonic CMS installation, even for a small site.

Why have caching been turned off? That should actually lead to less memory usage, but greater load and slower performance.

Read more about tuning the memory and cache of Enonic CMS here:

Sincerely,
Jørgen Sivesind

This happens in Enonic XP where image caching is not implemented.Typically the images that the customer uploads are about 5000x2000 pixels.

-Petter-

Oh. Sorry. I’ll leave it for the XP team to answer then. :blush:

Hi Petter.
As a default we use 2GB Heap on our installations. Can you try to increase your heap size to 2GB?

1GB Is a minimum and with your large images, this will quickly fill up your heap.