resource-pool-0.3.1.0: A high-performance striped resource pooling implementation
Safe Haskell None
Language Haskell2010

Data.Pool.Introspection

Description

A variant of Data.Pool with introspection capabilities.

Synopsis

Pool

data PoolConfig a Source #

Configuration of a Pool .

Constructors

PoolConfig

Fields

  • createResource :: !( IO a)

    The action that creates a new resource.

  • freeResource :: !(a -> IO ())

    The action that destroys an existing resource.

  • poolCacheTTL :: ! Double

    The amount of seconds for which an unused resource is kept around. The smallest acceptable value is 0.5 .

    Note: the elapsed time before destroying a resource may be a little longer than requested, as the collector thread wakes at 1-second intervals.

  • poolMaxResources :: ! Int

    The maximum number of resources to keep open across all stripes. The smallest acceptable value is 1 .

    Note: for each stripe the number of resources is divided by the number of capabilities and rounded up. Therefore the pool might end up creating up to N - 1 resources more in total than specified, where N is the number of capabilities.

data Pool a Source #

Striped resource pool based on Control.Concurrent.QSem .

The number of stripes is arranged to be equal to the number of capabilities so that they never compete over access to the same stripe. This results in a very good performance in a multi-threaded environment.

data LocalPool a Source #

A single, capability-local pool.

newPool :: PoolConfig a -> IO ( Pool a) Source #

Create a new striped resource pool.

The number of stripes is equal to the number of capabilities.

Note: although the runtime system will destroy all idle resources when the pool is garbage collected, it's recommended to manually call destroyAllResources when you're done with the pool so that the resources are freed up as soon as possible.

Resource management

data Resource a Source #

A resource taken from the pool along with additional information.

Instances

Instances details
Eq a => Eq ( Resource a) Source #
Instance details

Defined in Data.Pool.Introspection

Show a => Show ( Resource a) Source #
Instance details

Defined in Data.Pool.Introspection

Generic ( Resource a) Source #
Instance details

Defined in Data.Pool.Introspection

Associated Types

type Rep ( Resource a) :: Type -> Type Source #

type Rep ( Resource a) Source #
Instance details

Defined in Data.Pool.Introspection

withResource :: Pool a -> ( Resource a -> IO r) -> IO r Source #

withResource with introspection capabilities.

tryWithResource :: Pool a -> ( Resource a -> IO r) -> IO ( Maybe r) Source #

A variant of withResource that doesn't execute the action and returns Nothing instead of blocking if the capability-local pool is exhausted.

tryTakeResource :: Pool a -> IO ( Maybe ( Resource a, LocalPool a)) Source #

A variant of takeResource that returns Nothing instead of blocking if the capability-local pool is exhausted.

putResource :: LocalPool a -> a -> IO () Source #

Return a resource to the given LocalPool .

destroyResource :: Pool a -> LocalPool a -> a -> IO () Source #

Destroy a resource.

Note that this will ignore any exceptions in the destroy function.

destroyAllResources :: Pool a -> IO () Source #

Destroy all resources in all stripes in the pool.

Note that this will ignore any exceptions in the destroy function.

This function is useful when you detect that all resources in the pool are broken. For example after a database has been restarted all connections opened before the restart will be broken. In that case it's better to close those connections so that takeResource won't take a broken connection from the pool but will open a new connection instead.

Another use-case for this function is that when you know you are done with the pool you can destroy all idle resources immediately instead of waiting on the garbage collector to destroy them, thus freeing up those resources sooner.