package idle
Import Path
google.golang.org/grpc/internal/idle (on go.dev)
Dependency Relation
imports 4 packages, and imported by one package
Involved Source Files
Package idle contains a component for managing idleness (entering and exiting)
based on RPC activity.
Package-Level Type Names (total 2, both are exported)
ClientConn is the functionality provided by grpc.ClientConn to enter and exit
from idle mode.
( ClientConn) EnterIdleMode()
( ClientConn) ExitIdleMode()
*google.golang.org/grpc.idler
func NewManager(cc ClientConn, timeout time.Duration) *Manager
Manager implements idleness detection and calls the ClientConn to enter/exit
idle mode when appropriate. Must be created by NewManager.
// Count of active RPCs; -math.MaxInt32 means channel is idle or is trying to get there.
// Boolean; True if there was an RPC since the last timer callback.
actuallyIdle bool
Can be accessed without atomics or mutex since these are set at creation
time and read-only after that.
// Functionality provided by grpc.ClientConn.
// Boolean; True when the manager is closed.
idleMu is used to guarantee mutual exclusion in two scenarios:
- Opposing intentions:
- a: Idle timeout has fired and handleIdleTimeout() is trying to put
the channel in idle mode because the channel has been inactive.
- b: At the same time an RPC is made on the channel, and OnCallBegin()
is trying to prevent the channel from going idle.
- Competing intentions:
- The channel is in idle mode and there are multiple RPCs starting at
the same time, all trying to move the channel out of idle. Only one
of them should succeed in doing so, while the other RPCs should
piggyback on the first one and be successfully handled.
State accessed atomically.
// Unix timestamp in nanos; time when the most recent RPC completed.
timeout time.Duration
timer *time.Timer
Close stops the timer associated with the Manager, if it exists.
EnterIdleModeForTesting instructs the channel to enter idle mode.
ExitIdleMode instructs m to call the ClientConn's ExitIdleMode and update its
internal state.
OnCallBegin is invoked at the start of every RPC.
OnCallEnd is invoked at the end of every RPC.
UnsafeSetNotIdle instructs the Manager to update its internal state to
reflect the reality that the channel is no longer in IDLE mode.
N.B. This method is intended only for internal use by the gRPC client
when it exits IDLE mode **manually** from `Dial`. The callsite must ensure:
- The channel was **actually in IDLE mode** immediately prior to the call.
- There is **no concurrent activity** that could cause the channel to exit
IDLE mode *naturally* at the same time.
handleIdleTimeout is the timer callback that is invoked upon expiry of the
configured idle timeout. The channel is considered inactive if there are no
ongoing calls and no RPC activity since the last time the timer fired.
(*Manager) isClosed() bool
(*Manager) resetIdleTimer(d time.Duration)
resetIdleTimerLocked resets the idle timer to the given duration. Called
when exiting idle mode or when the timer fires and we need to reset it.
Return value indicates whether or not the channel moved to idle mode.
Holds idleMu which ensures mutual exclusion with exitIdleMode.
func NewManager(cc ClientConn, timeout time.Duration) *Manager
Package-Level Functions (only one, which is exported)
NewManager creates a new idleness manager implementation for the
given idle timeout. It begins in idle mode.
Package-Level Variables (only one, which is unexported)
The pages are generated with Golds v0.8.4. (GOOS=linux GOARCH=amd64)