tags:

views:

534

answers:

2

I have a Struts 1 web application that needs to upload fairly large files (>50 MBytes) from the client to the server. I'm currently using its built-in org.apache.struts.upload.DiskMultipartRequestHandler to handle the HTTP POST multipart/form-data requests. It's working properly, but it's also very very slow, uploading at about 100 KBytes per second.

Downloading the same large files from server to client occurs greater than 10 times faster. I don't think this is just the difference between the upload and download speeds of my ISP because using a simple FTP client to transfer the file to the same server takes less than 1/3 the time.

I've looked at replacing the built-in DiskMultipartRequestHandler with the newer org.apache.commons.fileupload package, but I'm not sure how to modify this to create the MultipartRequestHandler that Struts 1 requires.

Barend commented below that there is a 'bufferSize' parameter that can be set in web.xml. I increased the size of the buffer to 100 KBytes, but it didn't improve the performace. Looking at the implementation of DiskMultipartRequestHandler, I suspect that its performance could be limited because it reads the stream one byte at a time looking for the multipart boundary characters.

Is anyone else using Struts to upload large files?

Has anyone customized the default DiskMultipartRequestHandler supplied with Struts 1?

Do I just need to be more patient while uploading the large files? :-)

Thank you, Randy Stegbauer

+1  A: 

The page StrutsFileUpload on the Apache wiki contains a bunch of configuration settings you can use. The one that stands out for me is the default buffer size of 4096 bytes. If you haven't already, try setting this to something much larger (but not excessively large as a buffer is allocated for each upload). A value of 2MB seems reasonable. I suspect this will improve the upload rate a great deal.

Barend
That's a great idea! I didn't notice that before. Thanks! Unfortunately, I just now tried it and it didn't really make a difference.
Randy Stegbauer
+1  A: 

Use Apache Commons, this gives more flexibility to upload file . We can configure upload file size (Max file size) and temporary file location for swapping the file (this improves performance). please visit this link http://commons.apache.org/fileupload/using.html

Thomman
I see that this implementation is more flexible and even allows keeping the entire upload in memory before you decide to store it to disk. However what about it will affect very large (>50 MBytes) files?
Randy Stegbauer
This will not load entire file into memory before store to disk. Please use this fileItem.write(destination);
Thomman