> socket Handles are unbuffered by the default, so 
> if you change the buffering by inserting 
> 
>   hSetBuffering handle
>                 (BlockBuffered Nothing) -- or some such
> 
> after each call to socketToHandle / Socket.accept, you
> should get a boost in throughput.

Definitely - using the unbuffered sockets is likely to be slow due to the
overhead of GHC's I/O library.

If you're sending files over a socket, you can avoid the conversion to/from
Haskell Strings altogether, using GHC's hGetBuf/hPutBuf family (this is some
code from the web server):

bufsize = 4 * 1024 :: Int

-- squirt data from 'rd' into 'wr' as fast as possible.  We use a 4k
-- single buffer.
squirt rd wr = do
  arr <- stToIO (newCharArray (0, bufsize-1))
  let loop = do r <- hGetBufBAFull rd arr bufsize
        if (r == 0) 
                   then return ()
                   else if (r < bufsize) 
                            then hPutBufBAFull wr arr r
                            else hPutBufBAFull wr arr bufsize >> loop
  loop

Cheers,
        Simon

_______________________________________________
Glasgow-haskell-bugs mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to