Beware: Bad I/O performance on Windows without -threaded

Simon Marlow marlowsd at gmail.com
Tue Dec 21 17:12:33 CET 2010


I just noticed that I/O performane on Windows without -threaded is 
pretty terrible.  The following program:

main = getConetnts >>= putStr

tested with a 1MB file:

$ rm cat.exe; ghc-7.0.1 --make -rtsopts cat.hs
$ ./cat <1M >/dev/null +RTS -s
<snip>
   Total time    0.28s  (  0.49s elapsed)
<snip>

But if we add -threaded:

$ rm cat.exe; ghc-7.0.1 --make -rtsopts cat.hs -threaded
$ ./cat <1M >/dev/null +RTS -s
<snip>
   Total time    0.05s  (  0.07s elapsed)
<snip>

Several times better.  I just made a tweak in my working tree to 
increase the I/O buffer sizes, and this helps quite a lot:

$ rm cat.exe; ../ghc-testing/inplace/bin/ghc-stage2.exe --make -rtsopts 
cat.hs
$ ./cat <1M >/dev/null +RTS -s
<snip>
   Total time    0.06s  (  0.05s elapsed)
<snip>

$ rm cat.exe; ../ghc-testing/inplace/bin/ghc-stage2.exe --make -rtsopts 
cat.hs -threaded
$ ./cat <1M >/dev/null +RTS -s
<snip>
   Total time    0.05s  (  0.05s elapsed)
<snip>


Why is this?  I'm not entirely sure, but I suspect it is the 
implementation of asynchronous I/O in the RTS that is only used on 
Windows without -threaded (rts/win32/AsyncIO.c etc.).  Every I/O 
operation in the non-threaded RTS on Windows involves a couple of 
OS-thread switches.

I'll get the buffer size fixes into 7.0.2.

Cheers,
	Simon



More information about the Glasgow-haskell-users mailing list