-- | Connection pool configuration.
module Arbiter.Core.PoolConfig
  ( PoolConfig (..)
  , defaultPoolConfig
  ) where

-- | Connection pool configuration.
data PoolConfig = PoolConfig
  { PoolConfig -> Int
poolSize :: Int
  -- ^ Maximum connections
  , PoolConfig -> Int
poolIdleTimeout :: Int
  -- ^ Idle timeout (seconds)
  , PoolConfig -> Maybe Int
poolStripes :: Maybe Int
  -- ^ Sub-pools. 'Nothing' picks one per CPU.
  }
  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)

-- | 10 connections, 300s idle timeout, 1 stripe. For workers, size the pool
-- with 'Arbiter.Worker.poolConfigForWorkers'.
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
    }