resource-pool

A high-performance striped resource pooling implementation

LTS Haskell 24.54:0.4.0.0
Stackage Nightly 2026-08-16:0.5.1.0
Latest on Hackage:0.5.1.0

See all snapshots resource-pool appears in

BSD-3-Clause licensed by Andrzej Rybczak, Bryan O'Sullivan
Maintained by [email protected]
This version can be pinned in stack with:resource-pool-0.5.1.0@sha256:d335648228caccd4ee8ba23e85db089df07b016e672f235e8078ac97f1debd19,2398

Module documentation for 0.5.1.0

resource-pool

CI Hackage Stackage LTS Stackage Nightly

A high-performance striped resource pooling implementation for Haskell based on QSem.

Advice for library authors

If your library creates a pool on behalf of its users, don’t expose your own, restricted set of pool parameters (size, TTL, …) and construct the PoolConfig internally. Such a config inevitably lags behind features of this library (stripe count, labels, whatever comes next) and users can’t take advantage of them without waiting for you to mirror each one.

Instead, take a function of type IO a -> (a -> IO ()) -> PoolConfig a as a parameter. Your library supplies the resource creation and destruction actions:

createConnectionPool
  :: ConnectionSettings
  -> (IO Connection -> (Connection -> IO ()) -> PoolConfig Connection)
  -> IO (Pool Connection)
createConnectionPool settings mkPoolConfig =
  newPool $ mkPoolConfig connect disconnect
  where
    connect :: IO Connection
    connect = ...

    disconnect :: Connection -> IO ()
    disconnect = ...

while users retain full control over the rest of the pool configuration:

pool <- createConnectionPool settings $ \create free ->
  setPoolLabel "db"
    . setNumStripes (Just 1)
    $ defaultPoolConfig create free 60 10

Changes

resource-pool-0.5.1.0 (2026-08-15)

  • Spawn a collector thread per stripe and make them wake up when appropriate instead of polling every second.

resource-pool-0.5.0.1 (2026-07-08)

  • Fix a bug where a thread waiting for a resource would get stuck in the queue indefinitely if resource creation failed in another thread.
  • Fix a potential out-of-bounds array access in stripe selection when the hash of a thread id is negative.
  • Fix a bug where some of the stripes would never be used if the number of stripes was larger than the number of capabilities.
  • Add a test suite.

resource-pool-0.5.0.0 (2025-06-13)

  • Drop support for GHC < 8.10.
  • Use STM based lockless implementation as it results in much better throughput in a multi-threaded environment when number of stripes is not equal to the number of capabilities (in particular with a single stripe).
  • Stop running resource freeing functions within uninterruptibleMask.
  • destroyResource no longer ignores exceptions thrown from resource releasing functions.
  • Change the default number of stripes to 1.
  • Do not exceed the maximum number of resources if the number of stripes does not divide it.
  • Add support for assigning a label to the pool.

resource-pool-0.4.0.0 (2023-01-16)

  • Require poolMaxResources to be not smaller than the number of stripes.
  • Add support for setting the number of stripes.
  • Hide the constructor of PoolConfig from the public API and provide defaultPoolConfig so that future additions to PoolConfig don’t require major version bumps.

resource-pool-0.3.1.0 (2022-06-15)

  • Add tryWithResource and tryTakeResource.

resource-pool-0.3.0.0 (2022-06-01)

  • Rewrite based on Control.Concurrent.QSem for better throughput and latency.
  • Make release of resources asynchronous exceptions safe.
  • Remove dependency on monad-control.
  • Expose the .Internal module.
  • Add support for introspection.
  • Add PoolConfig.