Skip to content

Program gets stuck at 100% CPU usage on a Mac

Summary

This program gets stuck at 100% CPU even when idling after it finished its work. The program is just posting messages to the queue. (You need to have RabbitMQ running). The problem seems to arise when you have a sufficiently large message payload. It seems to always be good with 1 MB, and always bad with 2 MB. In between (such as 1.5 MB) it is sometimes good and sometimes bad -- so there isn't a simple byte threshold where the problem starts.

module Lib
    ( someFunc
    ) where

import Data.Monoid ((<>))
import Data.Word (Word8)
-- import qualified MyNetwork.AMQP as AMQP      <-- a copy of the AMQP code with tracing added
import qualified Network.AMQP as AMQP
import qualified Data.ByteString.Lazy as LBS


someFunc :: IO ()
someFunc = do
    putText "Starting"

    conn <- AMQP.openConnection''
                AMQP.defaultConnectionOpts
                    { AMQP.coServers        = [("queue.service", 5672)]
                    , AMQP.coVHost          = "/"
                    , AMQP.coAuth           = [AMQP.plain "indicee" "indicee"]
                    , AMQP.coHeartbeatDelay =  Just 10
                    }
    putText "RabbitMP Connection established"
    chan <- AMQP.openChannel conn
    putText "Channel opened"

    let msgContent =
            AMQP.newMsg { AMQP.msgBody =
                                -- LBS.replicate (1024 * 1) (fromIntegral 55)      --  <-- This is Ok
                                LBS.replicate (1024 * 1024 * 5) (55 :: Word8)      --  <-- This causes CPU to get stuck at 100%
                        , AMQP.msgDeliveryMode = Just AMQP.Persistent
                        }

    let routingKey = "Test.Test"

    putText "Starting publish"
    res <- AMQP.publishMsg chan "workResultExchange" routingKey msgContent
    putText $ "Finished publish:  result = " <> show res

    putText "<press Enter to finish>"
    _ <- getLine -- wait for keypress
    AMQP.closeConnection conn
    putText "connection closed"
    putText "DONE"


putText = putStrLn

Note that this issue is only reproducible on Mac systems. You will also need to have RabbitMQ running

I also attached process snapshot. largemsgtest_process_snap

Steps to reproduce

You need stack (sorry!)

  1. git clone https://github.com/nineonine/large_msg_test
  2. stack build
  3. stack exec largemsgtest-exe
  4. Observe that the program gets stuck at 100% CPU

Expected behavior

CPU usage is reasonable.

Environment

  • GHC version used: 8.4.4

Optional:

  • Operating System: Mac OS X 10.14.3 (18D109)
  • System Architecture:
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information