
Hi all, I've just pushed a relatively minor change to the WAI spec to Github, which ties off the last hole in the specification I'm aware of. One annoyance in creating streaming responses is the issue of flushing. By using Builders, it's more difficult to make a truly streaming, realtime app, as the server will wait until a buffer is filled before sending any data to the client. This is actually a very easy problem to solve. blaze-builder provides a value called `flush` that forces the buffer to be sent, even if it's not full. The problem arises when we add one more piece: the gzip middleware. With gzip, we have an extra layer of buffering in place.[1] We need some way to force gzip to flush the buffer as well. I've put together patches to zlib-bindings, conduit, blaze-builder-conduit, zlib-conduit, and wai, that do the following: * zlib-bindings can now explicitly flush a buffer. * conduit exposes a new datatype: `data Flush a = Chunk a | Flush` * blaze-builder-conduit exposes a new function: builderToByteStringFlush, that keeps flush boundaries intact * zlib-conduit similarly has compressFlush/decompressFlush * The type of ResponseSource now has a stream of `Flush Builder` instead of `Builder` I've updated the affected WAI packages. This may seem like a major overhaul, but it actually has very limited scope. The plus side is that we can now easily do something like an eventsource app that has gzip compression applied. Please let me know your thoughts on this, or if people know of any other holes in WAI that should be plugged right now as well. Michael [1] Regarding previous discussions of using a ByteString instead of a Builder for the stream: this issue would affect either a Builder or ByteString approach, and is thus an orthogonal issue.

Hello,
I've just pushed a relatively minor change to the WAI spec to Github, which ties off the last hole in the specification I'm aware of. One annoyance in creating streaming responses is the issue of flushing. By using Builders, it's more difficult to make a truly streaming, realtime app, as the server will wait until a buffer is filled before sending any data to the client. This is actually a very easy problem to solve. blaze-builder provides a value called `flush` that forces the buffer to be sent, even if it's not full.
This sounds good. I updated all necessary libraries and tried to compile wai-app-file-cgi. I got the following error. ---- Couldn't match expected type `Flush Builder' with actual type `Builder' Expected type: Source IO (Flush Builder) Actual type: Source IO Builder In the third argument of `ResponseSource', namely `src' In the second argument of `($)', namely `(ResponseSource st hdr' src)' ---- I don't understand how to fix. Are there any example implementations for proxy? --Kazu

On Thu, Jan 26, 2012 at 9:29 AM, Kazu Yamamoto
Hello,
I've just pushed a relatively minor change to the WAI spec to Github, which ties off the last hole in the specification I'm aware of. One annoyance in creating streaming responses is the issue of flushing. By using Builders, it's more difficult to make a truly streaming, realtime app, as the server will wait until a buffer is filled before sending any data to the client. This is actually a very easy problem to solve. blaze-builder provides a value called `flush` that forces the buffer to be sent, even if it's not full.
This sounds good.
I updated all necessary libraries and tried to compile wai-app-file-cgi. I got the following error.
---- Couldn't match expected type `Flush Builder' with actual type `Builder' Expected type: Source IO (Flush Builder) Actual type: Source IO Builder In the third argument of `ResponseSource', namely `src' In the second argument of `($)', namely `(ResponseSource st hdr' src)' ----
I don't understand how to fix. Are there any example implementations for proxy?
Without seeing the code in question, I would try: ResponseSource st hdr' $ fmap Chunk src This would create a stream without any flushing, which is what the previous behavior supported. Michael

Without seeing the code in question, I would try: ResponseSource st hdr' $ fmap Chunk src
This would create a stream without any flushing, which is what the previous behavior supported.
Ah. OK. Now I can compile wai-app-file-cgi. Thank you for your help. So, we should specify the Flash constructor when we want to flush the buffer, right? --Kazu

On Thu, Jan 26, 2012 at 10:38 AM, Kazu Yamamoto
Without seeing the code in question, I would try: ResponseSource st hdr' $ fmap Chunk src
This would create a stream without any flushing, which is what the previous behavior supported.
Ah. OK. Now I can compile wai-app-file-cgi. Thank you for your help.
So, we should specify the Flash constructor when we want to flush the buffer, right?
--Kazu
Correct. Here's an example program: https://gist.github.com/1681814 Michael

Looks good to me! It's a simple interface and completely solves the flushing problem. =) Cheers, -- Felipe.
participants (3)
-
Felipe Almeida Lessa
-
Kazu Yamamoto
-
Michael Snoyman