• Post Reply Bookmark Topic Watch Topic
  • New Topic

The fastet way to stream data to the response in a servlet ?  RSS feed

 
Frank Jacobsen
Ranch Hand
Posts: 358
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a url, where I need to stream the content 1MB as fast as possible back to the client, back in the response...

This works fine, but can I do it faster ?

Maybe is the fastet way, if it is, can anyone confirm this ?



1) I open my OutputSream
2) New Url with nt docommentUrl // Is a http url
3) Open a inputstream on my url
4) Call a copy methoed, that copyes 8192 bytes from input stream, to
Output stream, and make a out.write, så no big memory foot print.
5) and last, make a flush !




Frank

 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With an 8K buffer, the loop will run at least 128 times for a 1MB stream. If the buffer was 1MB, there's a possibility that the loop will run only a single time, which should be a bit faster. Or is this in a memory-constrained environment?
 
Frank Jacobsen
Ranch Hand
Posts: 358
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No it isent, i will try this, and see if this is faster

Thanks for the advise
 
Frank Jacobsen
Ranch Hand
Posts: 358
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just tried to take the time for the whole methoed where the loop executes and its under 50 milliseconds each time:

[09-05-29 11:32:24:684 CEST] 00000057 SystemOut O time in loop frank: 16

Here 16 milisecunds, so there is not much to gain here

// Frank
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!