ImageIO.read/write slow in Websphere 8.5.5

795 views Asked by At

As a part of my web application, I am using javax.imageio.ImageIO for reading/writing BufferedImage. Initially my app was running on Tomcat 7, and it was running quite fast. Since I've deployed my app to WebSphere 8.5.5 the performance of reading/writing has significantly decreased (few times slower).

At first, I thought was that ImageIO performed bad on WebSphere due to IBM's JVM, so I've configured Tomcat to use IBM Java, and again it performed much better then on WebSphere. With Tomcat it takes around 2.5secs and with WebSphere 12secs to read, process, and write the image (size ~= 200KB).

Is there some IBM JVM specific configuration I can use in order to speed up reading of images?

Here is the extract from the code I use:

// srcImagePath & dstImagePath are both pointing 
// to the location outside app servers

BufferedImage image = ImageIO.read(new File(srcImagePath));

// here I am only resizing image using com.twelvemonkeys.image.ResampleOp
// from twelvemonkeys library
BufferedImage destImage = resizeImage(image);

ImageIO.write(destImage, "jpg", dstImagePath);

Here is the JVM configuration I have used (changed):

Tomcat 7.0.50: -Xms512m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=512m

WebSphere 8.5.5: Initial heap size 512m, Maximum heap size: 1280m

IBM Java 1.7_64

Windows 7

Is there any WebSphere configuration I am not aware of, that could speed up the processing?

1

There are 1 answers

6
Igor On

After the profiling, I've found the reason for the slow response.

Most of the time consumed in WebSphere during image processing was caused by ResampleOp class, specifically:

com.twelvemonkeys.image.ResampleOp.resample

method was the bottleneck for image resize process. With native Java's AffineTransform I was not able to get good quality resized images, therefore I've ended up using imgscalr library. imgscalr performs very good in my case (both Tomcat & WebSphere) and with good quality pics.

I am still using Twelvemonkey's JPEGImageReader, for correct reading of CMYK JPEG images.

UPDATE:

Resize code I had with ResampleOP was:

ResampleOp resampleOp = new ResampleOp(width, height);
BufferedImage rescaledImage = resampleOp.filter(image, null);

With the Scalr, code I'm using now is:

BufferedImage rescaledImage = Scalr.resize(image, width, height);