Documentation ¶
Overview ¶
Package workpool provies the `Pool` type which functions as a means of managing the number of concurrent workers, grouped by key. You can think of this type as functioning like a collection of semaphores, except that multiple distinct resources may exist (distinguished by keys), and the target concurrent worker count may change at runtime. The basic usage pattern is as follows:
1. The desired number of workers for a given key is specified or updated via Pool.Set.
2. Workers are spawned as leases become available on Pool.Acquire.
3. Workers relenquish their leases when they finish their work by calling Lease.Release.
4. New leases become available as old leases are relenquished, or as the target concurrent lease count increases.
This is a generalization of logic originally written to manage the number of concurrent reversetunnel agents per proxy endpoint.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Counts ¶
type Counts struct { // Target is the number of active leases that we would // like to converge toward. Target uint64 // Active is the current active lease count. Active uint64 }
Counts holds the target and active counts for a key/group.
type Lease ¶
type Lease struct {
// contains filtered or unexported fields
}
Lease grants access to a resource or group. When the lease is received, work can begin. Leases are held by workers and must be released when the worker has finished its work.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool manages a collection of work group by key and is the primary means by which group are managed. Each work group has an adjustable target value which is the number of target leases which should be active for the given group.
func (*Pool) Acquire ¶
Acquire is the channel which must be received on to acquire new leases. Each lease acquired in this way *must* have its Release method called when the lease is no longer needed. Note this channel will deliver leases from all active work group. It's up to the receiver to differentiate what group the lease refers to and act accordingly.