2

I'm able to extract contents from the request object through an input stream. So if it is a stream, does it mean the data is being transferred 'live' from the client to the servlet through os->webcontainer->etc etc ?

If I pass large amount of data in the request, does it get cached somewhere at the OS/JVM or is it being read directly from the source live? Can I open a request inputStream to tera/peta bytes of data, and write it to an outputstream byte by byte without any problems (ignoring the amount of time it would take and time outs) ?

Update if they are getting cached, why are they streams? which can be read only just one time (and need to be stored) once opened, instead they should be available to be read as many times as needed.

Just random queries, no practical use.

Rnet
  • 4,326
  • 9
  • 42
  • 81
  • For example, for Tomcat: http://stackoverflow.com/questions/2943477/is-there-a-max-size-for-post-parameter-content – Victor Sorokin Jun 10 '13 at 21:05
  • Interesting; but leaving vendor specific implementations, what is the nature of input/outstreams? are they ultimately getting cached at some level? If so why are they streams? which can be read only one time. If cached, we could reread them again and again – Rnet Jun 10 '13 at 21:10
  • nature is left unspecified by 'Sun/Oracle servlets spec' (you can google for it, and then try to find any mentions of underlying impl. -- there's none). I guess, these are simply data passed over _single_ TCP connection, so there's no explicit caching (maybe, only implicit page swapping by OS in case of huge POST queries not fitting into RAM entirely) – Victor Sorokin Jun 10 '13 at 21:15
  • Then, you can always look inside Tomcat/Jetty/whatever source code and see for yourself. But, most probably, it's just a single TCP connection going on, without explicit caching. – Victor Sorokin Jun 10 '13 at 21:19
  • @VictorSorokin Thanks :) I'm going to try and see if I can transfer a 100MB file byte by byte – Rnet Jun 10 '13 at 21:22

1 Answers1

1

They're not cached. If something's been cached, it's available for re-use. Those streams are however not reusable and thus definitely not cached.

However, it's quite possible that they're buffered in memory or even on local disk file system instead of memory. This is fully to decision of the server implementation and even the underlying operating system (also known as "virtual disk" or "swap disk", depending on the operating system used). This buffer is however usually not as large as orders of magnitude of a megabyte. For example, the standard Java SE BufferedInputStream class has an internal buffer of 8KB.

Can I open a request inputStream to tera/peta bytes of data, and write it to an outputstream byte by byte without any problems (ignoring the amount of time it would take and time outs) ?

You may hit the HTTP POST size limit which is usually configurable on the server. This defaults in for example Tomcat to 2GB, but can entirely be disabled. See also the maxPostSize setting on the HTTP connector.

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452