Thanks again for the info, Chris. Please excuse the formatting, I am attempting to respond inline to the points below.
On Thu, May 20, 2010 at 6:16 PM, Christopher Schultz <ch...@christopherschultz.net> wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Ðavîd, > > On 5/20/2010 5:30 PM, Ðavîd Låndïs wrote: >> I think it is "streaming" although it does use a buffered writer like >> I mentioned before. > > Sure, but if you use a buffered writer to simply dump a huge byte array, > that's not exactly streaming. What I meant, I guess was, does your code > look like this: > > Writer out = new PrintWriter(new BufferedWriter(response.getWriter())); > > generateCSVdata(out); > > or, does your code look like this: > > String CSVdata = generateCSVdata(); > > Writer out = new PrintWriter(new BufferedWriter(response.getWriter())); > > out.write(CSVdata); Yes my code is like the former. It is "streaming". > > In both cases, the client can only download the data at a certain rate, > so it'll "feel" like it's "streaming", but in the latter case, you've > done 100% of the work before the first byte is delivered to the client. No, the work is not done before hand. That is what I meant in previous email, "Basically, I: generate a line of data, write to the print writer and then repeat". > > Assuming you have code like the former, you'll have to wait for an > exception indicating that the client has closed the connection and your > generateCSVdata process should be interrupted. If you're not > experiencing any interruptions, it could be due to any of the following > reasons: I am not experiencing any interruptions which is my problem. I am hoping to find a way to get an interruption. > > a. You have a really large buffer Could be I guess, but even when I tried to manually flush the writer, I am not getting an exception. > b. You have such little data that you can't cancel fast enough No, I can cancel and the application continues streaming data for several minutes. > c. You generate data much faster than you think you do No I debugged it and it keeps writing to the printwriter for several minutes after I cancel the download on the client computer. > d. The connection doesn't actually close right away Could be, I am not familiar with what is actually supposed to happen in this scenario. This seems pretty likely I guess but I was hoping Tomcat would have some way of knowing that it was cancelled and close it. > e. There is something else doing a significant amount of buffering > (which is why Chuck asked about the presence of httpd out in front) Again, the server continues to write a lot of data -- 10+ megs after the user cancels. > > I'm sure there are other possibilities. Are you observing a long-running > generation of data that just doesn't terminate when the client hangs up > the phone? Yes. > If so, try looking at netstat to see what the status is at > the socket level, etc. If you can't cause a long enough content > generation step, you can always loop over your generateCSVdata call as a > test, or introduce artificial delays into the code (think Thread.sleep) > to give yourself some time for observations during those critical moments. Good call on the netstat, I will try that. > >> The PrintWriter flushes itself along the way > > Do you mean as a natural course of buffering, or do you explicitly call > out.flush() periodically? You'll get better performance and throughput > if you don't explicitly call out.flush (except at the very end, when > you've run out of content). I am not explicitly calling flush. But I have tried that as a test. Yes I noticed it was slower as well. > > - -chris > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.10 (MingW32) > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ > > iEYEARECAAYFAkv1tNIACgkQ9CaO5/Lv0PCOfgCeMce85js+pQElSIG8cvJXIZTN > tkkAoLcacn5pNy2tLOMLjz/j9Wyed06e > =ejzF > -----END PGP SIGNATURE----- > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org > For additional commands, e-mail: users-h...@tomcat.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org