#2891: threadDelay appears to use excessive CPU in GHCi
---------------------------+------------------------------------------------
    Reporter:  JeremyShaw  |        Owner:         
        Type:  bug         |       Status:  closed 
    Priority:  normal      |    Milestone:         
   Component:  Compiler    |      Version:  6.8.3  
    Severity:  normal      |   Resolution:  wontfix
    Keywords:              |   Difficulty:  Unknown
    Testcase:              |           Os:  Linux  
Architecture:  x86         |  
---------------------------+------------------------------------------------
Changes (by simonmar):

  * status:  new => closed
  * difficulty:  => Unknown
  * resolution:  => wontfix

Comment:

 Ok, this program repeatedly waits for one second.  When this is run with
 the threaded RTS, here's what happens:

   * the program calls threadDelay
   * 1/3 of a second later, the RTS notices that the program is idle and
 does
     a GC
   * after 1 second, the program wakes up again, etc.

 so we get a full GC every second, which accounts for the 2% CPU usage: in
 GHCi there's about 5Mb of stuff in the heap when idle.  You'll see the
 same effect when compiling the program with `-threaded`, but there the
 heap will be almost empty, so the GC won't take much time.  Without
 `-threaded` there is no idle-time GC.

 You can turn off the idle-time GC with the `-I0` RTS option, e.g.
 {{{
 ghci +RTS -I0
 }}}

 The idle-time GC isn't there just for performance reasons, it's also for
 detecting deadlock.  If the program has deadlocked, the only way to detect
 that (and send `BlockedIndefinitely` exceptions) is to do a GC, but we
 want to wait until the program looks idle before initiating the GC, hence
 the current behaviour.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2891#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to