Documentation
¶
Overview ¶
Package sessionpool keeps one live backend process per key, reused across jobs and closed once it has been idle.
A provider CLI's startup floor is seconds — measured at ~8.5s warm and up to ~128s cold on the slowest agent — and a batch queue that starts a fresh process per source pays it every time. Reusing one process across the whole queue pays it once. The pool is keyed (by provider name, in draft's use) so two request kinds routed to the same provider share a process, while two different providers each keep their own; and it closes a process that has gone unused for the idle interval so a stalled or finished queue does not hold a subprocess open forever.
The pool is generic over a Session — anything that can report whether it is still alive and can be closed — so it is exercised in tests with a fake. The engine's ACP agent connection satisfies it directly and is pooled through it by the ACP engine.
Lock order is entry before pool, never the reverse: Get holds an entry's lock across a slow start and then consults the pool map, so anything that held the pool lock while waiting for an entry would deadlock against it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool is a set of keyed, reused sessions with an idle close policy. The zero value is not usable; construct one with New. A Pool is safe for concurrent use.
func New ¶
New returns a pool that closes a session after it has been idle for at least idle. An idle of zero means a released session is eligible to be reaped immediately.
func (*Pool) CloseAll ¶
func (p *Pool) CloseAll()
CloseAll closes every live session and empties the pool, regardless of idle time or in-use count. It is the end-of-queue shutdown: nothing should be borrowing when it runs, but it does not wait for borrowers.
func (*Pool) Get ¶
Get returns a live session for key, starting one with start if the key has none or its session has died. The returned session is marked in use until a matching Release, so it cannot be reaped while a caller holds it. A start error is returned and leaves the key with no live session.
func (*Pool) Reap ¶
Reap closes and drops every session that is not in use and has been idle for at least the pool's idle interval. It returns how many it closed. Call it periodically (a ticker) to bound how long an unused process lingers.
An entry whose lock is held is skipped rather than waited for: someone is borrowing it or starting its session, so it is not idle, and waiting would stall every Reap caller behind a start that can take minutes.
type Session ¶
type Session interface {
// Alive reports whether the session is still usable. A process that has
// exited returns false, and the pool starts a replacement.
Alive() bool
// Close shuts the session down. The pool calls it once per session, when
// the session is reaped or the pool is closed.
Close() error
}
Session is a reusable, closable backend process. draft's ACP agent connection satisfies it.