Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Advice on MultipartConfig fileSizeThreshold

I have a Servlet with the following annotation, very basic.

@MultipartConfig
 (
      fileSizeThreshold = 1024 * 1024 * 1, // 1 MB
      maxFileSize = 1024 * 1024 * 30, // 30 MB
      maxRequestSize = 1024 * 1024 * 35, // 35 MB
      location = "/somewhere"
  )

The reason for my post is the setting, fileSizeThreshold. As I understand it, fileSizeThreshold sets the threshold for holding the file in memory before it's written to disk. I understand that the default is 0, and in the above code snippet, once 1mb was reached with an incoming file it would start to be written to disk.

What is the point of this setting? Is there an advantage to increasing the amount of the file in memory before a write?

I have an application where 80% of file uploads are <5mb, but we do get bigger files in the 25-30mb range. We're even looking at increasing the max to 50mb.

Every article I can find on MultipartConfig describes what fileSizeThreshold does but not how/when to use it... does anyone have any advice given the file requirements in the previous paragraph? If it makes a difference, we run glassfish4 on a ubuntu box.

Thanks in advance!

like image 689
cotfessi Avatar asked Dec 16 '15 20:12

cotfessi


1 Answers

The idea with fileSizeThreshold is a bit misleading, because it's a straightforward mechanism, but the actual use case for it seems so rare that it makes you question whether or not you are understanding the property correctly.

You are correct in saying that it is the point at which a file will be persisted to disk. Note that by default, this is 0, so by default files will get written to disk, which is what you want probably 99% of the time.

The fileSizeThreshold comes in handy when your files have a short lifespan and come in at a high rate such that persisting the files to disk incurs a significant performance overhead. You could set this param to be something above 0 to save yourself some disk i/o.

The reason why having a threshold is significant versus having a boolean which would always keep files in memory is to give yourself a safety net for not keeping files that are too large in memory (for obvious reasons).

like image 199
Andy Guibert Avatar answered Oct 18 '22 22:10

Andy Guibert