View Source Reactor.Executor.ConcurrencyTracker (reactor v0.4.0)

Manage shared concurrency pools for multiple Reactors.

When running a Reactor you can pass the concurrency_key option, which will cause the Reactor to use the specified pool to ensure that the combined Reactors never exceed the pool's available concurrency limit.

This avoids nested Reactors spawning too many workers and thrashing the system.

Summary

Functions

Attempt to acquire a concurrency allocation from the pool.

Allocate a new concurrency pool and set the maximum limit.

Returns a specification to start this module under a supervisor.

Release a concurrency allocation back to the pool.

Release the concurrency pool.

Report the available and maximum concurrency for a pool.

Types

@type pool_key() :: reference()

Functions

@spec acquire(pool_key()) :: :ok | :error

Attempt to acquire a concurrency allocation from the pool.

Returns :ok if the allocation was successful, otherwise :error.

Link to this function

allocate_pool(concurrency_limit)

View Source
@spec allocate_pool(non_neg_integer()) :: pool_key()

Allocate a new concurrency pool and set the maximum limit.

Returns a specification to start this module under a supervisor.

See Supervisor.

@spec release(pool_key()) :: :ok

Release a concurrency allocation back to the pool.

@spec release_pool(pool_key()) :: :ok

Release the concurrency pool.

This deletes the pool, however doesn't affect any processes currently using it. No more resources can be acquired by users of the pool key.

@spec status(pool_key()) :: {:ok, available, limit} | {:error, any()}
when available: non_neg_integer(), limit: pos_integer()

Report the available and maximum concurrency for a pool.