[GHC] #8733: I/O manager causes unnecessary syscalls in send/recv loops

GHC ghc-devs at haskell.org
Sun Feb 9 05:11:48 UTC 2014


#8733: I/O manager causes unnecessary syscalls in send/recv loops
--------------------------------------------+------------------------------
        Reporter:  tibbe                    |            Owner:
            Type:  bug                      |           Status:  new
        Priority:  normal                   |        Milestone:  7.10.1
       Component:  Runtime System           |          Version:  7.6.3
      Resolution:                           |         Keywords:
Operating System:  Unknown/Multiple         |     Architecture:
 Type of failure:  Runtime performance bug  |  Unknown/Multiple
       Test Case:                           |       Difficulty:  Unknown
        Blocking:                           |       Blocked By:
                                            |  Related Tickets:
--------------------------------------------+------------------------------

Comment (by AndreasVoellmy):

 When you say simplify, what are you comparing to? Is there some
 implementation of those functions that you are thinking of?

 Maybe you mean that those functions are implemented in a way similar to
 the`timeout :: Int -> IO a -> IO (Maybe a)` function in `System.Timeout`.
 I haven't measured the performance of `timeout` but I imagine it isn't
 very good, since it forks a new thread in each call. We do have a couple
 new functions in 7.8 that might allow us to provide a more efficient
 implementation than something like`timeout` . In 7.8, we have these
 functions:

 `threadWaitReadSTM :: Fd -> IO (STM (), IO ())`
 `threadWaitWriteSTM :: Fd -> IO (STM (), IO ())`

 They return an STM action that completes whenever the given file is ready
 to read (or write). Then we can use it in combination with `registerDelay
 :: Int -> IO (TVar Bool)` to wait on both the file and the timer without
 spawning a new thread. It would be something like this:

 {{{#!haskell
 threadWaitReadWithTimeout :: Fd -> Int -> IO Bool
 threadWaitReadWithTimeout fd n =
  do { (ready, _) <- threadWaitReadSTM fd;
        alarm <- registerDelay n;
        atomically ((ready >> return True)`orElse`
                    (readTVar alarm >>= check >> return False))
      }
 }}}

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8733#comment:16>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list