Skip to content

Commit

Permalink
Raise default number of workers
Browse files Browse the repository at this point in the history
Now the default number of workers will be one less than the number
of cores on the system, with a minimum of 1 and a maximum of 3.
  • Loading branch information
elopez committed Jul 15, 2024
1 parent 08041e4 commit d514836
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions lib/Echidna/Types/Campaign.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ module Echidna.Types.Campaign where
import Control.Concurrent (ThreadId)
import Data.Aeson
import Data.Map (Map)
import Data.Maybe (fromMaybe)
import Data.Text (Text)
import Data.Text qualified as T
import Data.Word (Word8, Word16)
import GHC.Conc (numCapabilities)

import Echidna.ABI (GenDict, emptyDict, encodeSig)
import Echidna.Types
Expand Down Expand Up @@ -211,9 +211,14 @@ defaultSymExecAskSMTIters :: Integer
defaultSymExecAskSMTIters = 1

-- | Get number of fuzzing workers (doesn't include sym exec worker)
-- Defaults to 1 if set to Nothing
-- Defaults to (N-1) if set to Nothing, where N is Haskell's -N value,
-- usually the number of cores, clamped between 1 and 3.
getNFuzzWorkers :: CampaignConf -> Int
getNFuzzWorkers conf = fromIntegral (fromMaybe 1 (conf.workers))
getNFuzzWorkers conf = maybe defaultN fromIntegral conf.workers
where
n = numCapabilities
maxN = max 1 (n - 1) -- one dedicated thread for shrinking
defaultN = min 3 maxN -- capped at 3 by default

-- | Number of workers, including SymExec worker if there is one
getNWorkers :: CampaignConf -> Int
Expand Down
4 changes: 2 additions & 2 deletions tests/solidity/basic/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ rpcUrl: null
rpcBlock: null
# Etherscan API key
etherscanApiKey: null
# number of workers
workers: 1
# number of workers. By default (unset) its value is the clamp of (# cores - 1) between 1 and 3
workers: null
# events server port
server: null
# whether to add an additional symbolic execution worker
Expand Down

0 comments on commit d514836

Please sign in to comment.