[jira] [Created] (FILEUPLOAD-198) Add two optional parameters to FileUploadBase.getItemIterator() to pass temporary buffers similar to Streams.copy()

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Created] (FILEUPLOAD-198) Add two optional parameters to FileUploadBase.getItemIterator() to pass temporary buffers similar to Streams.copy()

Sebb (Jira)
Add two optional parameters to FileUploadBase.getItemIterator() to pass temporary buffers similar to Streams.copy()
-------------------------------------------------------------------------------------------------------------------

                 Key: FILEUPLOAD-198
                 URL: https://issues.apache.org/jira/browse/FILEUPLOAD-198
             Project: Commons FileUpload
          Issue Type: Improvement
    Affects Versions: 1.2.2
         Environment: Fedora 15. Tomcat 6.
            Reporter: Andreas Girgensohn
            Priority: Minor
             Fix For: 1.2.2


When processing a large number of multipart uploads, new byte buffers are created for every part of every request.  It would be preferable if the servlet could reuse those buffers for the next request.  Failing that, it would already be an improvement if FileUploadBase.findNextItem() could pass the same buffer to subsequent calls of MultipartStream.skipPreamble() and discardBodyData().

The item iterator would need two temporary buffers.  One would be passed to MultipartStream via a new constructor.  The other would be passed to readBodyData(), discardBodyData(), and skipPreamble() to be passed on to Streams.copy().

This change would require additional signatures for five methods constructors and methods but it would reduce memory allocation by a noticeable amount.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (FILEUPLOAD-198) Add two optional parameters to FileUploadBase.getItemIterator() to pass temporary buffers similar to Streams.copy()

Sebb (Jira)

    [ https://issues.apache.org/jira/browse/FILEUPLOAD-198?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13066347#comment-13066347 ]

Andreas Girgensohn commented on FILEUPLOAD-198:
-----------------------------------------------

If you don't want create additional method signatures, you could use the following in MultipartStream and Streams.

private static final int IO_BUFFER_SIZE = 8192;
private static final ThreadLocal<SoftReference<byte[]>> io_buffer_ref = new ThreadLocal<SoftReference<byte[]>> ();

protected static byte[] getIOBuffer () {
  byte[] io_buffer = null;
  SoftReference<byte[]> ref = io_buffer_ref.get ();
  if (ref != null)
    io_buffer = ref.get ();
  if (io_buffer == null) {
    io_buffer = new byte[IO_BUFFER_SIZE];
    io_buffer_ref.set (new SoftReference<byte[]> (io_buffer));
  }
  return io_buffer;
}

> Add two optional parameters to FileUploadBase.getItemIterator() to pass temporary buffers similar to Streams.copy()
> -------------------------------------------------------------------------------------------------------------------
>
>                 Key: FILEUPLOAD-198
>                 URL: https://issues.apache.org/jira/browse/FILEUPLOAD-198
>             Project: Commons FileUpload
>          Issue Type: Improvement
>    Affects Versions: 1.2.2
>         Environment: Fedora 15. Tomcat 6.
>            Reporter: Andreas Girgensohn
>            Priority: Minor
>             Fix For: 1.2.2
>
>
> When processing a large number of multipart uploads, new byte buffers are created for every part of every request.  It would be preferable if the servlet could reuse those buffers for the next request.  Failing that, it would already be an improvement if FileUploadBase.findNextItem() could pass the same buffer to subsequent calls of MultipartStream.skipPreamble() and discardBodyData().
> The item iterator would need two temporary buffers.  One would be passed to MultipartStream via a new constructor.  The other would be passed to readBodyData(), discardBodyData(), and skipPreamble() to be passed on to Streams.copy().
> This change would require additional signatures for five methods constructors and methods but it would reduce memory allocation by a noticeable amount.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira