samtay / tetris

A terminal interface for Tetris
Other
871 stars 40 forks source link

Problem: The CPU resource demand increases #34

Open MarkowEduard opened 8 months ago

MarkowEduard commented 8 months ago

If tetris is put into sleep mode with the pause command it starts to increase its demand of the CPU resource. After a few days pausing it consumes currently more than 25 parts of 100 on a 8 core CPU (i.e. 255.99%). Top shows

last pid: 18889;  load averages:  6.47,  6.29,  6.66                   up 330+11:44:16 13:34:35
470 processes: 2 running, 467 sleeping, 1 waiting
CPU: 44.6% user,  0.0% nice,  1.7% system,  0.1% interrupt, 53.5% idle
Mem: 7322M Active, 7881M Inact, 6698M Laundry, 8742M Wired, 502M Buf, 1170M Free
ARC: 3830M Total, 2307M MFU, 832M MRU, 800K Anon, 74M Header, 617M Other
     1725M Compressed, 5208M Uncompressed, 3.02:1 Ratio
Swap: 64G Total, 38G Used, 26G Free, 58% Inuse

  PID USERNAME    THR PRI NICE   SIZE    RES STATE    C   TIME    WCPU COMMAND
   11 root          8 155 ki31     0B   128K CPU0     0    ??? 428.23% idle
12283 xxxxxx       20  20    0   881M   801M uwait    3 153.3H 255.99% tetris
88553 yyyyyy        6  20    0   246M   124M uwait    5  91.4H  87.21% ghc-9.4.6

What's going on there? When put into sleep mode it starts with consuming only very little (1.12%) of the CPU resource: 18900 zzzzzz 20 20 0 121M 26M uwait 4 0:00 1.12% tetris

samtay commented 4 months ago

That's strange.. pause mode shouldn't really be doing anything other than running this forked thread:

void . forkIO $ forever $ do
  writeBChan chan Tick
  threadDelay delay

and brick's event handler handling those ticks:

handleEvent :: BrickEvent Name Tick -> EventM Name UI ()
handleEvent (AppEvent Tick) =  do
 ui <- get
    unless (ui ^. paused || ui ^. game . to isGameOver) $ do
      -- do normal game stuff
    -- but when paused, do nothing.

First reasonable thing to do would be to update the brick dependency, the version used here is quite old and this may have been fixed there.