https://issues.apache.org/bugzilla/show_bug.cgi?id=47660

           Summary: OutOfMemoryErrors when sending large file using HTTP
                    Sampler
           Product: JMeter
           Version: 2.3.4
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: HTTP
        AssignedTo: jmeter-dev@jakarta.apache.org
        ReportedBy: numberzero1...@gmail.com


--- Comment #0 from Hao Lin <numberzero1...@gmail.com> 2009-08-07 01:56:27 PDT 
---
I'm using JMeter-2.3.4 to test a HTTP Server nowadays, and find out that
JMeter can not send HTTP PUT or POST request with large files using HTTP
Sampler.

After reading the the code of HTTP sampler and making experiments with
HttpURLConnection class which is used in HTTP Sampler, I find out that it is
JMeter's misusing HttpURLConnection class that trigerd suck bug.

HttpURLConnection can add 'Content-Length' header automatically, so it will
buffer all the output stream before sending it in order to count the length
of the stream.  So when we want to send a large file, HttpURLConnection will
buffer it until stack overflow.

To fix the problem of PUT(which also exists in POST method) large file, I
modified the code of setHeaders
method of org.apache.jmeter.protocol.http.sampler.PutWriter class.
Here is a fragment of the modified code in setHeaders:

if(hasPutBody) {
   ///////////////modified place:////////////////
   // Set the content length
   // the following code makes no sense
   // since the HttpURLConnection can add Content-Length header
   // automatically
   // connection.setRequestProperty(HTTPConstants.HEADER_CONTENT_LENGTH,
   // Long.toString(contentLength));

   // set the HttpURLConnection to send fixed length stream
   // this code prevent HttpURLConnection to buffer output stream
   if(connection instanceof HttpURLConnection){
    ((HttpURLConnection)connection).setFixedLengthStreamingMode(contentLength);
   }
   ////////////////////end of modified place/////////////////////////


   // Make the connection ready for sending post data
   connection.setDoOutput(true);
}

As is shown in the code, I comment out the code
"connection.setRequestProperty(HTTPConstants.HEADER_CONTENT_LENGTH,
Long.toString(contentLength));" (since HttpURLConnection will add it
automatically later), and add "((HttpURLConnection)
connection).setFixedLengthStreamingMode(contentLength);", this tells
HttpURLConnection the fixed length of the request body and enables streaming
of a HTTP request body without internal buffering.

After making this modification, JMeter can send PUT HTTP request with large
files to my HTTP Server.

Regards
Hao Lin

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscr...@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-h...@jakarta.apache.org

Reply via email to