Hey, I've been having some memory usage issues getting snap to produce very large http responses. I've included the offending code at the end of this message. Basically test1 consumes a lot of memory, and test2 runs in a small constant amount of memory, where test1 is delivering data to a client and test2 is printing it to stdout. More details in the stackoverflow question I posted:
Stack overflow questionhttp://stackoverflow.com/questions/31901811/haskell-snap-memory-usage-for-large-http-response-bodiesAny help is very much appreciated!
Simon
The offending code:
import Snap.Core (Snap, writeLBS, readRequestBody)
import Snap.Http.Server (quickHttpServe)
import Control.Monad.IO.Class (MonadIO(liftIO))
import qualified Data.ByteString.Lazy.Char8 as LBS (ByteString, length, replicate)
main :: IO ()
main = quickHttpServe $ site test1 where
test1, test2 :: LBS.ByteString -> Snap ()
-- Send ss to client
test1 = writeLBS
-- Print ss to stdout upon receiving request
test2 = liftIO . print
site write = do
body <- readRequestBody 1000
-- Making ss dependant on the request stops GHC from keeping a
-- reference to ss as pointed out by Reid Barton.
let bodyLength = fromIntegral $ LBS.length body
write $ ss bodyLength
ss c = LBS.replicate (1000000000000 * (c + 1)) 'S'