workerpool

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package workerpool provides a two-level bounded-concurrency helper for the scanner (see §5 of scry-plan.md).

Two semaphores are exposed:

  • Host — bounds the number of hosts in flight (default 50).
  • Socket — bounds the total in-flight TCP sockets across all hosts (default 1000).

Both are acquired as weighted semaphores so the caller can release exactly what was acquired. The split keeps per-host latency predictable while still letting a single "busy" host use many sockets when others are idle.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Hosts   int // default 50
	Sockets int // default 1000
}

Config tunes pool capacity. Zero/negative values fall back to defaults.

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

Pool holds the two semaphores. Acquire in Host→Socket order and release in reverse to avoid starving other hosts while holding socket budget.

func New

func New(cfg Config) *Pool

New constructs a Pool.

func (*Pool) AcquireHost

func (p *Pool) AcquireHost(ctx context.Context) error

AcquireHost blocks until there is room for another host, or ctx is done.

func (*Pool) AcquireSocket

func (p *Pool) AcquireSocket(ctx context.Context) error

AcquireSocket blocks until there is a free socket slot, or ctx is done.

func (*Pool) HostLimit

func (p *Pool) HostLimit() int64

HostLimit returns the configured max in-flight hosts.

func (*Pool) ReleaseHost

func (p *Pool) ReleaseHost()

ReleaseHost releases a single host slot.

func (*Pool) ReleaseSocket

func (p *Pool) ReleaseSocket()

ReleaseSocket releases a single socket slot.

func (*Pool) SocketLimit

func (p *Pool) SocketLimit() int64

SocketLimit returns the configured max in-flight sockets.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL