• Post Reply Bookmark Topic Watch Topic
  • New Topic

ImageIO performance is very low in solaris compared to windows need an alternative  RSS feed

 
venkata vinay bysani
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

I need to write a JPEG image to an output stream. For this i am using the below code


These two lines when running in windows taking 60 to 80 milli seconds when running in solaris its taking 1200+ milli second which is more than a second.
The file i am using is same and the JVM is also the same in both windows and solaris

Why is this issue happening and is there any alternative for performing the above task.

 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you're trying to investigate performance issues in a piece of code, it's a good idea to break things down if you want to know where problems might be.

In your case you have two lines of code. So time them separately to try and identify which of them is the problem.
 
venkata vinay bysani
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please find the time taken for both the lines individually

In Windows
For line: bufferedImage = ImageIO.read(new File(...)); Time taken is 50 to 70ms
For line: ImageIO.write(bufferedImage,"jpg",outStream); Time taken is 30 to 40 ms

In Solaris
For line: bufferedImage = ImageIO.read(new File(...)); Time taken is 900 to 1100ms
For line: ImageIO.write(bufferedImage,"jpg",outStream); Time taken is 350 to 500 ms

and the Java version in both is 1.5
 
Jayesh A Lalwani
Rancher
Posts: 2762
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you just have a slower disk?
 
venkata vinay bysani
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think its the problem with the slower disk because i am also reading and writing CSV files (with file size grater than 1MB where as these images are less than 200kb) to the disk the time taken to read and write the CSV file is same in both windows and Solaris.

Is there any way to improve the performance of those two lines or is there any alternate approach to achieve the same which is a faster one.
 
Tony Docherty
Bartender
Posts: 3206
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does Java use the graphics processor to process the image rendering and if so are they similar spec processors on the two systems
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There shouldn't be much (or any) rendering happening in those two lines. It's just file I/O, and storing the raw data in bytes in some particular order.

It's quote possible that the Windows JVM is better optimized in these areas.
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reading through these documentations:

http://docs.oracle.com/javase/tutorial/2d/images/loadimage.html
http://docs.oracle.com/javase/tutorial/2d/images/saveimage.html

you'll notice that the ImageIO API is backed by plugin implementations for different formats of the image. So it's very much possible that the plugin implementation for a specific OS isn't performing as well as the plugin implementation for the same format on a different OS. I haven't personally given it a try across different OS to see if that's the case.

By the way, is this only with .jpg images or other formats too?
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, which exact vendor and version of Java is it on Windows and Solaris?


will show you the necessary information. I was just reading this documentation http://docs.oracle.com/javase/6/docs/technotes/guides/imageio/enhancements60.html and noticed that there have been some major bug fixes related to performance improvement for ImageIO in Java 6 and some of them seem applicable to Solaris (see the "Performance and resource management" section on that page and read through some of the linked bugs). So you might want to make sure you have the latest version of Java installed on these systems.

 
venkata vinay bysani
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reminding about vendor Jaikiran, after checking that I came to know in windows its Sun JVM but in Solaris its IBM's JVM
and we cant upgrade it to 1.6 as it is a server and lot of other applications running on it, this needs a lot of process to be done for an upgrade.

Is there any other way to achieve the same. I tried converting the image to byte array as a normal file by reading the bytes of the stream to a byte array but with that byte array the target system is showing the error as "java io exception: The byte array is not a recognized imageformat"

I tried to search for other ways to convert a JPG image (as we get only JPG images) to byte array ever where i am able to get the solution through ImageIO only which is not helpful for me.
Please let me know if there are any alternative of this process which would be fast or is there any thing we can do to improve the performance of this.
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
venkata vinay bysani wrote:after checking that I came to know in windows its Sun JVM but in Solaris its IBM's JVM

Do you want to use IBM JVM on Solaris? Why not just install Sun/Oracle JVM there too an use it?

 
Luke Kolin
Ranch Hand
Posts: 343
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I may be missing something, but why are we using ImageIO in the first place? You're decompressing then recompressing the image, which is why it's slow. Why not just stream the file contents without using ImageIO?

Cheers!

Luke
 
venkata vinay bysani
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Luke Kolin,

I want to send the image in a byte array format to the target system, if i read the image directly as a stream and convert that into byte array i am getting exception from the target system saying "the byte array is not a valid image format". If I read the image as buffered image and then convert to the byte array, in the way i am doing in the above code, then the target system is accepting the byte array with out any error.

Doing this error is not coming but performance is very slow. Is there any other way to perform the operation i am trying to do.

@Jaikiran Pai the target system is an IBM product so there are some dependencies with the IBM's JVM so we cant use the sun/oracle JVM
 
Carey Brown
Saloon Keeper
Posts: 2538
33
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the original file a JPG file?
 
venkata vinay bysani
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Carey Brown, Yes the file i am trying to convert is a JPG image file only
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!