module Arbiter.Core.PoolConfig
( PoolConfig (..)
, defaultPoolConfig
, poolConfigForWorkers
) where
import Control.Monad.IO.Class (MonadIO, liftIO)
import GHC.Conc (getNumCapabilities)
data PoolConfig = PoolConfig
{ PoolConfig -> Int
poolSize :: Int
, PoolConfig -> Int
poolIdleTimeout :: Int
, PoolConfig -> Maybe Int
poolStripes :: Maybe Int
}
deriving stock (PoolConfig -> PoolConfig -> Bool
(PoolConfig -> PoolConfig -> Bool)
-> (PoolConfig -> PoolConfig -> Bool) -> Eq PoolConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PoolConfig -> PoolConfig -> Bool
== :: PoolConfig -> PoolConfig -> Bool
$c/= :: PoolConfig -> PoolConfig -> Bool
/= :: PoolConfig -> PoolConfig -> Bool
Eq, Int -> PoolConfig -> ShowS
[PoolConfig] -> ShowS
PoolConfig -> String
(Int -> PoolConfig -> ShowS)
-> (PoolConfig -> String)
-> ([PoolConfig] -> ShowS)
-> Show PoolConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PoolConfig -> ShowS
showsPrec :: Int -> PoolConfig -> ShowS
$cshow :: PoolConfig -> String
show :: PoolConfig -> String
$cshowList :: [PoolConfig] -> ShowS
showList :: [PoolConfig] -> ShowS
Show)
defaultPoolConfig :: PoolConfig
defaultPoolConfig :: PoolConfig
defaultPoolConfig =
PoolConfig
{ poolSize :: Int
poolSize = Int
10
, poolIdleTimeout :: Int
poolIdleTimeout = Int
300
, poolStripes :: Maybe Int
poolStripes = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
1
}
poolConfigForWorkers :: (MonadIO m) => Int -> m PoolConfig
poolConfigForWorkers :: forall (m :: * -> *). MonadIO m => Int -> m PoolConfig
poolConfigForWorkers Int
workerCnt = do
caps <- IO Int -> m Int
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO Int
getNumCapabilities
let size = Int
workerCnt Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
5
let stripes = Int -> Int -> Int
forall a. Ord a => a -> a -> a
min Int
caps Int
size
pure
PoolConfig
{ poolSize = size
, poolIdleTimeout = 300
, poolStripes = Just stripes
}