|
The
performance bottleneck is the lack of a buffer to download/write the file and
the flush method invoked too often.
You're
writing a byte, then flushing, which sends a TCP/IP packet down the wire. Since
TCP/IP�packets have a 64 byte header and 512 bytes for data, you're wasting 511
bytes in each packet. Some app servers also have caches available, so this
interferes with that as well.
Try
this code:
try
{
bif = new BufferedInputStream(new FileInputStream("E:/abcd/download/xyz/"+fname)); stream = res.getOutputStream(); byte [] buf = new byte[8192]; // 8KB buffer int data;
while(( data = "bif.read(buf,0,8192))" != -1) { stream.write(buf, 0, data); // stream.flush(); } bif.close(); stream.close(); return res; } catch(Exception e) { System.out.println("The Exception is :"+e); } finally { if (stream != null) stream.close(); return res; } }//end of method Now,
you'll be reading in 8KB chunks, and writing in 8KB chunks as well. I commented
out the flush() method invocation, but you'll probably want to try with and
without it and see which performs better. Also feel free to tweak the size of
the buffer, always in 512 bytes increments and remember it should be at least
512 for optimum performance.
HTH,
Juan Pablo Lorandi
Chief Software
Architect
Code Foundry Ltd.
Barberstown, Straffan, Co. Kildare, Ireland. Tel: +353-1-6012050 Fax: +353-1-6012051 Mobile: +353-86-2157900 www.codefoundry.com Disclaimer:
Opinions expressed are entirely
personal and bear no relevance to opinions held by my employer.
Code Foundry Ltd.'s opinion is that I
should get back to work.
|
Title: Message
- Performance improvement of Download Code ssmtech
- Re: Performance improvement of Download Code Dmitri Colebatch
- Re: Performance improvement of Download Code Anshul Dutta, Noida
- Which caching strategy to employ ? Juan Pablo Lorandi
- Which caching strategy to employ ? Paul Kavanagh
