Efferent-Health / fo-dicom.Codecs

Cross-platform Dicom native codecs for fo-dicom
Other
64 stars 22 forks source link

Allow to configure the threshold size that is used to decide whether to create a TempFileBuffer or a MemoryByteBuffer #48

Closed amoerie closed 11 months ago

amoerie commented 11 months ago

Is your feature request related to a problem? Please describe. In the Fellow Oak 4 codecs (now removed in v5), our company had made custom changes to the codecs. One of these was increasing the default (hardcoded) value of 1 MB, which decides whether to create a TempFileBuffer or a MemoryByteBuffer when encoding a frame.

The reason is that we process nearly more than a million DICOM files per day, and what we see is that our cloud servers have ample memory to spare, but the disk is more of a bottle neck. Most of the disk activity comes from... the temp files of the codecs. By increasing the threshold to 10 MB or even 100 MB, our throughput increases drastically.

Refer to formal documentation This snippet is taken from DicomJpegLsCodec:

if (jpegDataSize >= (1 * 1024 * 1024) || oldPixelData.NumberOfFrames > 1)
{
    buffer = new TempFileBuffer(jpegData);
    buffer = EvenLengthBuffer.Create(buffer);
}
else
    buffer = new MemoryByteBuffer(jpegData);

As far as I can see, this kind of code lives in 6 places: image

Specifically, I would like the ability for an application to override the default value 1 * 1024 * 1024 A public static option would suffice for me, or maybe a property on NativeTranscoderManager.

Provide source code See above

jaime-olivares commented 11 months ago

Hi @amoerie, I have published a nuget beta: https://www.nuget.org/packages/fo-dicom.Codecs/5.10.9-beta1 Use the static field NativeTranscoderManager.MemoryBufferThresholdfor setting the threshold in bytes. Let me know how it goes.

amoerie commented 11 months ago

Thanks @jaime-olivares for the super speedy response! It'll be a while before we can actually test this in production, but the changes look perfect! 🙏