From 3b5d6d93a501d6e9cd649c51dfdb08361be83412 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20L=C3=B3pez?= <2642849+elopez@users.noreply.github.com> Date: Tue, 16 Jul 2024 14:08:19 +0200 Subject: [PATCH] Raise default number of workers (#1288) Now the default number of workers will be equal to the number of cores on the system, with a minimum of 1 and a maximum of 4. --- lib/Echidna/Types/Campaign.hs | 11 ++++++++--- tests/solidity/basic/default.yaml | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/Echidna/Types/Campaign.hs b/lib/Echidna/Types/Campaign.hs index 78a885189..b54c19185 100644 --- a/lib/Echidna/Types/Campaign.hs +++ b/lib/Echidna/Types/Campaign.hs @@ -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 @@ -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` if set to Nothing, where `N` is Haskell's -N value, +-- usually the number of cores, clamped between 1 and 4. getNFuzzWorkers :: CampaignConf -> Int -getNFuzzWorkers conf = fromIntegral (fromMaybe 1 (conf.workers)) +getNFuzzWorkers conf = maybe defaultN fromIntegral conf.workers + where + n = numCapabilities + maxN = max 1 n + defaultN = min 4 maxN -- capped at 4 by default -- | Number of workers, including SymExec worker if there is one getNWorkers :: CampaignConf -> Int diff --git a/tests/solidity/basic/default.yaml b/tests/solidity/basic/default.yaml index d9c277287..fc52ab1cc 100644 --- a/tests/solidity/basic/default.yaml +++ b/tests/solidity/basic/default.yaml @@ -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 the number cores between 1 and 4 +workers: null # events server port server: null # whether to add an additional symbolic execution worker