Here is my new code:
protected String getFile(HttpServletRequest req) throws IOException {
String file = null;
DataInputStream in = null;
String contentType = req.getContentType();
in = new DataInputStream(req.getInputStream());
int formDataLength = req.getContentLength();
byte dataBytes[] = new byte[formDataLength];
int bytesRead = 0;
for (int totalBytesRead = 0;
totalBytesRead < formDataLength;
totalBytesRead += bytesRead)
bytesRead = in.read(dataBytes, totalBytesRead, formDataLength);
file = new String(dataBytes);
in.close();
return file;
}
I did some timings with passing a 28k http/xml request to the servlet and noticed some
strange results. Running 1 client in a loop of 25 times the routine will take
anywhere from 25 milliseconds to 7 seconds to execute. If I put some stress on it (5
virtual users) the routine can take from 25 milliseconds to 20 seconds to execute.
Any ideas ????
On Wed, 1 Aug 2001 09:31:52 -0500, Christopher K. St. John <[EMAIL PROTECTED]>
wrote:
>John Zink wrote:
>>
>> Could you send me an example of StringBuffer pooling ?
>> I am not quite sure what you mean.
>>
>
>
> Forget the StringBuffer pooling (with a modern JVM it
>probably won't help much anyway). Your problem is that
>touching bytes/chars one at a time is deadly slow. Fix
>your reader to read/append arrays. Bonus points if you
>can make the array as big as the request (so you end
>up with a single read and a single append). You can
>muck around further trying for more performance, but
>fix the one-char-at-a-time problem first. (If you've
>already done that, never mind :-)
>
>
>--
>Christopher St. John [EMAIL PROTECTED]
>DistribuTopia http://www.distributopia.com
>
>___________________________________________________________________________
>To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
>of the message "signoff SERVLET-INTEREST".
>
>Archives: http://archives.java.sun.com/archives/servlet-interest.html
>Resources: http://java.sun.com/products/servlet/external-resources.html
>LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html