[GHC] #8400: Migrate the RTS to use libuv (or libev, or libevent)

GHC ghc-devs at haskell.org
Fri Aug 11 02:55:04 UTC 2017


#8400: Migrate the RTS to use libuv (or libev, or libevent)
-------------------------------------+-------------------------------------
        Reporter:  schyler           |                Owner:  (none)
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Runtime System    |              Version:
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:  635, 7353         |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by winter):

 Another thing to add is that, recently experiments showed that it's
 important to make a balance between unsafe nonblocking poll, e.g.
 `epoll_wait` with timeout zero and safe blocking poll, e.g. `epoll_wait`
 with timeout -1.

 Currently mio do two non-blocking poll, if still no events happend, mio
 sleep by doing a blocking poll. In stdio i use a idle counter, increased
 by one if last poll return no events. When the counter reach a
 limit(currently 50), stdio sleep by doing a blocking poll(using libuv's
 `UV_RUN_ONCE` mode).

 While this number doesn't affect normal load situation(since you never
 enter blocking poll in that case),  it affect some light load situation,
 namely some benchmark code. The idle counter solution and 50 as a limit
 are borrowed from golang, which helped it win lots of benchmark i guess.
 In that case, mio just enter safe FFI too often.

 The mechanism is actually more complicated in stdio, since libuv never
 guarantee thread safety except a special `uv_async_t` handler(which behave
 like a control FD). We have to wake up the safe blocking call everytime we
 add new events. But this also give stdio a better ratio between unsafe and
 safe poll: everytime we wake from a blocking poll, we clean the idle
 counter so next 50 time poll will be unsafe one.

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


More information about the ghc-tickets mailing list