You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by "Rich Scheuerle (JIRA)" <ji...@apache.org> on 2007/07/12 21:31:04 UTC

[jira] Reopened: (AXIS2-2946) Attachment Perf Improvement

     [ https://issues.apache.org/jira/browse/AXIS2-2946?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Rich Scheuerle reopened AXIS2-2946:
-----------------------------------


As part of this fix, I replaced the following code:

do {
                        int len;
                        int off = 0;
                        int rem = fileStorageThreshold;
                        while ((len = partStream.read(buffer, off, rem)) > 0) {
                            off = off + len;
                            rem = rem - len;
                        }
                        count += off;
                    } while (partStream.available() > 0);

with

 count = partStream.read(buffer).

The "old code" is definitely wrong.  Notice that the buffer is over-written if the while loop is repeated.
However the "new code" could possibly fail if the underlying stream delivers the bytes in chunks (not sure if that could actually happen).

I am testing a fix right now that uses the following logic:


/**
     * Read bytes into the buffer until full or until the EOS
     * @param is
     * @param buffer
     * @return number of bytes read
     * @throws IOException
     */
    private static int readToBuffer(InputStream is, byte[] buffer) throws IOException {
        int index = 0;
        int remainder = buffer.length;
        do {
            int bytesRead;
            while ((bytesRead = is.read(buffer, index, remainder)) > 0) {
                index += bytesRead;
                remainder -= bytesRead;
            }
        } while (remainder > 0 && is.available() > 0);  // repeat if more bytes are now available
        return index;
    }

Kudos to Thilina for reviewing this patch.

> Attachment Perf Improvement
> ---------------------------
>
>                 Key: AXIS2-2946
>                 URL: https://issues.apache.org/jira/browse/AXIS2-2946
>             Project: Axis 2.0 (Axis2)
>          Issue Type: Improvement
>          Components: kernel
>            Reporter: Rich Scheuerle
>            Assignee: Rich Scheuerle
>
> I am working on  a performance improvement improvement reading attachments.
> Currently the Axiom Attachments code reads bytes until it surpasses the file threshold.  If the file threshold is high (i.e. 100M) this causes a very large buffer to be created....even if the attachment is stored on file.
> The improvement is to use the content-length  of the message as a heuristic to determine if the attachments should be flushed to file.
> This improves performance and memory footprint.
> The first part of the change is to add an Axiom Attachment constructor to axiom that accepts a content-length parameter.  If the content-length is set, then the the heuristic is used.
> The second part of the change is to add code to the Axis2 kernel builder to pass in the content-length.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-dev-help@ws.apache.org