Re: Issue with GM through JNI
Bob Friesenhahn <[email protected]>
| Newsgroups | gmane.comp.video.graphicsmagick.help |
|---|---|
| Message-ID | <[email protected]> |
On Tue, 18 Jul 2017, Tianyu Lang wrote: > > However, we noticed MagickWriteImageBlob is taking almost a second. We > tracked down the function that is being slow and found out the code flow is > as follows: > `MagickWriteImageBlob` -> `ImageToBlob` -> 'WriteImage' -> 'png_write_row' > > Just to reaffirm our intuition, does MagickWriteImageBlob use WritePNGImage > in order to normalize the raw image? Yes, it does. The way the blob functionality works is that I/O routines to memory (rather than a file) are used with the existing encoders/decoders. > And is there any particular reason why png_write_row of the libpng library > might be taking almost 800-900ms? If it matters, we are attempting to use > this function in parallel from multiple Java threads. Glenn (libpng maintainer and GM PNG maintainer) would know more about this topic than I would, but in my experience most time spent encoding PNG format is spend in the zlib compressor. The encoding time can be significantly reduced by requesting lower quality compression. See the documentation for '-quality' in the GM utility documentation for information on how the quality factor can be used to influence how PNGs are compressed. Since PNG is lossless, a low quality factor may result in a larger file (hopefully encoded in less time) but the image will be identical. On some operating systems setjmp/longjmp are not thread safe (e.g. perhaps longjmp does not fully restore the CPU state). The SETJMP_IS_THREAD_SAFE definition (e.g. -DSETJMP_IS_THREAD_SAFE=1) may be used when configuring GraphicsMagick in order to avoid semaphoring within the PNG coder which would allow only one thread to use the PNG coder at a time. Use this if you think that setjmp/longjmp are thread safe on your operating system since it will then allow multiple threads to use PNG at the same time. Bob -- Bob Friesenhahn [email protected], http://www.simplesystems.org/users/bfriesen/ GraphicsMagick Maintainer, http://www.GraphicsMagick.org/ ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot