Java Mailing List Archive

http://www.junlu.com/

Google
Google
Mailing List
Home
Forum Home
JBoss - Java Application Server
Tomcat - JSP/Servlet container
Struts - A MVC web framework
iText - An open source PDF Java Library
JDOM - JDOM XML Parser
JSP - A mailing list about Java Server Pages specification and reference
J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition
J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog
Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology
Struts & Hibernate
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Subject: Servlet : Session invalidate
Oracle Connection Pooling in 3 2 2
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Subject: Running a Simple JMS Example
Tomcat and webapplication specific java library path
Mapping in workers2 properties
org apache jasper JasperException
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action
   MESSAGE
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
Value attribute of <html:checkbox
url string for connecting jboss to oracle
javax servlet ServletException: BeanUtils populate
5 0 18: Windows XP Pro vs Windows 2000
HTTP Status 404 The requested resource is not available
 
performance problem with ServletOutputStream.write()

performance problem with ServletOutputStream.write()

2005-01-17       - By Jean-Christian Imbeault

 Back
I previously asked the list about a performance problem I had while
reading files of disk and then streaming them to clients.

I didn't notice there was a 'problem' until I compare the time it takes
our application to stream the file to our users vs. the time it takes
out application server (acting a plain web server) to serve up the same
file. Streaming takes about 5x longer!

Many people suggested that I read and write the file from the
presentation layer servlet in order to save on objects, memory, etc ...

I did this and to my surprise I barely saw any improvements at all in
the speed at which the pdf file is streamed. I added lots of 'debugging'
code to find out where the bottleneck was and was shocked to see that
almost all the time spent (about 90%) is when I sent the file back to
the client by calling ServletOutputStream.write().

I'm pretty much out of ideas on how to 'fix' this since there really is
no other to send something to the client than to write() to the
OuputStream as far as I know.

The code basically boils down to:

read file off disk using BufferedInputStream
write file using ServletOutputStream.write()

That's it. Nothing else. I can't see any way to improve this code.

Can someone shed light on why streaming is so much slower at
transmitting files than a 'regular' web server?

Is there anything I can do to improve my situation?

Thanks!

Sample code and output from a test case is included below:


ServletOutputStream out = res.getOutputStream();
buff = new byte[fileLength];

startDate = new Date();
System.out.println("PERF: " + userIDForPDFPerformance
   + " :FiDServlet:doPost\t-BEGIN    :" + startDate
   + " *** CASE 5 READ ***");

bis.read(buff, 0, buff.length);
endDate = new Date();
System.out.println("PERF: " + userIDForPDFPerformance
   + " :FiDServlet:doPost\t-END      :" + endDate + " Time Diff:" +
(endDate.getTime() - startDate.getTime()) / 1000.0
   + " *** CASE 5 READ ***");

startDate = new Date();
System.out.println("PERF: " + userIDForPDFPerformance
   + " :FiDServlet:doPost\t-BEGIN    :" + startDate
   + " *** CASE 5 WRITE ***");
out.write(buff, 0, buff.length);
endDate = new Date();
System.out.println("PERF: " + userIDForPDFPerformance
   + " :FiDServlet:doPost\t-END      :" + endDate + " Time Diff:" +
(endDate.getTime() - startDate.getTime()) / 1000.0
   + " *** CASE 5 WRITE ***");


==SAMPLE OUTPUT==

PERF: -121*35*-3 :FiDServlet:doPost     -BEGIN    :Mon Jan 17 16:34:46 JST
2005 *** CASE 5 READ ***
PERF: -121*35*-3 :FiDServlet:doPost     -END      :Mon Jan 17 16:34:46 JST
2005 Time Diff:0.0050 *** CASE 5 READ ***
PERF: -121*35*-3 :FiDServlet:doPost     -BEGIN    :Mon Jan 17 16:34:46 JST
2005 *** CASE 5 WRITE ***
PERF: -121*35*-3 :FiDServlet:doPost     -END      :Mon Jan 17 16:34:53 JST
2005 Time Diff:6.739 *** CASE 5 WRITE ***

===========================================================================
To unsubscribe, send email to listserv@(protected) and include in the body
of the message "signoff J2EE-INTEREST".  For general help, send email to
listserv@(protected) and include in the body of the message "help".

©2008 junlu.com - Jax Systems, LLC, U.S.A.