Striped resource pool based on Control.Concurrent.QSem.
Moduleresource-pool-0.4.0.0Haskell2010
Data.Pool.Introspection
A variant of Data.Pool with introspection capabilities.
- 5 types
- 10 values
- Packageresource-pool-0.4.0.0
- Exports15
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceIntrospection.hs
Pool
3 declarationsA single, local pool.
Create a new striped resource pool.
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.
Configuration
Configuration of a Pool.
defaultPoolConfig :: IO aThe action that creates a new resource.
-> (a -> IO ())The action that destroys an existing resource.
-> DoubleThe 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.
-> IntThe 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 stripes and rounded up, hence the pool might end up creating up to
N - 1resources more in total than specified, whereNis the number of stripes.-> PoolConfig a
Create a PoolConfig with optional parameters having default values.
For setting optional parameters have a look at:
Set the number of stripes in the pool.
If set to Nothing (the default value), the pool will create the amount of stripes equal to the number of capabilities. This ensures that threads never compete over access to the same stripe and results in a very good performance in a multi-threaded environment.
Resource management
9 declarationsA resource taken from the pool along with additional information.
Constructors
Resourceresource :: astripeNumber :: !IntavailableResources :: !Intacquisition :: !AcquisitionacquisitionTime :: !DoublecreationTime :: !Maybe Double
Instances4Eq, Show, Generic, Rep
Eq a => Eq (Resource a)Defined in resource-pool-0.4.0.0 · Data.Pool.IntrospectionShow a => Show (Resource a)Defined in resource-pool-0.4.0.0 · Data.Pool.IntrospectionGeneric (Resource a)Defined in resource-pool-0.4.0.0 · Data.Pool.Introspectiontype Rep (Resource a) = D1 ('MetaDataDefined in resource-pool-0.4.0.0 · Data.Pool.Introspection"Resource"
"Data.Pool.Introspection"
"resource-pool-0.4.0.0-6ocmdeFECLbACyBFxgi7yL"
'False) (C1 ('MetaCons"Resource"
'PrefixI 'True) ((S1 ('MetaSel ('Just"resource"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: (S1 ('MetaSel ('Just"stripeNumber"
) 'NoSourceUnpackedness 'SourceStrict 'DecidedUnpack) (Rec0 Int) :*: S1 ('MetaSel ('Just"availableResources"
) 'NoSourceUnpackedness 'SourceStrict 'DecidedUnpack) (Rec0 Int))) :*: (S1 ('MetaSel ('Just"acquisition"
) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Acquisition) :*: (S1 ('MetaSel ('Just"acquisitionTime"
) 'NoSourceUnpackedness 'SourceStrict 'DecidedUnpack) (Rec0 Double) :*: S1 ('MetaSel ('Just"creationTime"
) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe Double))))))
Describes how a resource was acquired from the pool.
Instances4Eq, Show, Generic, Rep
Eq AcquisitionDefined in resource-pool-0.4.0.0 · Data.Pool.IntrospectionShow AcquisitionDefined in resource-pool-0.4.0.0 · Data.Pool.IntrospectionGeneric AcquisitionDefined in resource-pool-0.4.0.0 · Data.Pool.Introspectiontype Rep Acquisition = D1 ('MetaDataDefined in resource-pool-0.4.0.0 · Data.Pool.Introspection"Acquisition"
"Data.Pool.Introspection"
"resource-pool-0.4.0.0-6ocmdeFECLbACyBFxgi7yL"
'False) (C1 ('MetaCons"Immediate"
'PrefixI 'False) U1 :+: C1 ('MetaCons"Delayed"
'PrefixI 'False) U1)
withResource with introspection capabilities.
takeResource with introspection capabilities.
A variant of withResource that doesn't execute the action and returns Nothing instead of blocking if the local pool is exhausted.
A variant of takeResource that returns Nothing instead of blocking if the local pool is exhausted.
Return a resource to the given LocalPool.
Destroy a resource.
Note that this will ignore any exceptions in the destroy function.
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.