bioformats icon indicating copy to clipboard operation
bioformats copied to clipboard

bfconvert very slow when converting to ome.tiff to a disk where writing is "slow"

Open anntzer opened this issue 2 years ago • 8 comments

I have a metamorph nd acquisition (a nd file and "many" tiff files: 27 positions x 55 time points, each of the 512x1024 16-bit pixels -- overall ~1.5Gb) on a network drive. Downloading the acquisition to my local disk takes 22s, converting that acquisition to an ome.tiff with bfconvert takes ~1min, then reuploading the resulting single ome.tiff to the network drive takes 45s. In fact, I don't even need to pre-download the data: I can also let bfconvert directly take the data on the network drive as input and write the ome.tiff on my local disk; this takes essentially the same amount of time as if the data has been downloaded first.

On the other hand, if I try to make bfconvert directly write the resulting ome.tiff file on the network drive, then things become extremely slow: the conversion takes ~30min. My entirely unsubstantiated guess is that this may be because bfconvert perhaps tries to make many short writes, rather than buffering the output internally and emit bigger blocks at once?

anntzer avatar Apr 19 '23 17:04 anntzer

Thanks @anntzer for raising the issue, this is something we will likely have to profile to determined exactly which operations are causing the reduced performance.

dgault avatar Apr 20 '23 17:04 dgault

Let me know if I can help with that.

anntzer avatar Apr 20 '23 17:04 anntzer

@dgault Anything I can do to move this forward? I can try profiling if you can point me to instructions on how to do that.

anntzer avatar Jun 13 '23 19:06 anntzer

Hi @anntzer, if you were able to do some profiling that would be a great help. One tool I would recommend using would be VisualVM.

If you open VisualVM and start the bfconvert tool, you should see loci.formats.tools.ImageConverter under the list of applications. Screenshot 2023-06-14 at 15 14 19

If you click on loci.formats.tools.ImageConverter and then select profiler. From here you can select CPU, Memory or JDBC. If you select CPU, then this should give you a list which you can expand to show which calls are taking the most time. If you expand the list of the most time consuming calls as far down as you can you will start to see something similar to below: Screenshot 2023-06-14 at 15 16 08

If you could save that profile snapshot or get a good screen grab of the expanded list of calls, that should be a good starting point to highlight the root cause of the issue.

dgault avatar Jun 14 '23 14:06 dgault

There it is. bfconvert

Looking at it, I guess AbstractNIOHandle.setLength (https://github.com/ome/ome-common-java/blob/eafa3055e12e450b14a85f878a31b6a1ce6e81a2/src/main/java/loci/common/NIOFileHandle.java#L227) is perhaps a bit inefficient in that it only reserves exactly the amount of space requested, and allocating that space in bigger chunks (with some slack) could perhaps help. (But I don't know how to build the library to try...)

anntzer avatar Jun 14 '23 16:06 anntzer

Thanks @anntzer, was that for the full file? If so it looks like the majority of the time is spent writing the metadata values rather than the pixel data, so it seems to be the large number of writes for the metadata that is the bottleneck. Actually, looking back it seems we had tried to solve a similar issue with the pixel data previously, so a similar solution may be possible for the metadata values as well: https://github.com/ome/bioformats/pull/3239

dgault avatar Jun 15 '23 15:06 dgault

The previous run was not for a full file (I ctrl-c'd at some point), because it takes so long; here's a full run: visualvm setLength seems to account for ~2/3 of the total runtime.

anntzer avatar Jun 15 '23 16:06 anntzer

This issue has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/pyramidometiffwriter-really-bad-performance-when-closing-the-writer/95294/9

imagesc-bot avatar Jun 27 '24 06:06 imagesc-bot