Class SessionPoolOptions (2.21.0)

Controls the session pool maintained by a spanner::Client.

Creating Cloud Spanner sessions is an expensive operation. The recommended practice is to maintain a cache (or pool) of sessions in the client side. This class controls the initial size of this pool, and how the pool grows (or shrinks) as needed.

Constructors

SessionPoolOptions()

Functions

EnforceConstraints(int)

Enforce the stated constraints on the option values, altering them if necessary.

This can't be done in the setters, since we don't yet know the number of channels, and it would also constrain the order in which the fields must be set.

num_channels the number of RPC channels in use by the pool.

Parameter
NameDescription
num_channels int
Returns
TypeDescription
SessionPoolOptions &

set_min_sessions(int)

Set the minimum number of sessions to keep in the pool.

Values <= 0 are treated as 0. This value will effectively be reduced if it exceeds the overall limit on the number of sessions (max_sessions_per_channel * number of channels).

Parameter
NameDescription
count int
Returns
TypeDescription
SessionPoolOptions &

min_sessions() const

Return the minimum number of sessions to keep in the pool.

Returns
TypeDescription
int

set_max_sessions_per_channel(int)

Set the maximum number of sessions to create on each channel.

Values <= 1 are treated as 1.

Parameter
NameDescription
count int
Returns
TypeDescription
SessionPoolOptions &

max_sessions_per_channel() const

Return the minimum number of sessions to keep in the pool.

Returns
TypeDescription
int

set_max_idle_sessions(int)

Set the maximum number of sessions to keep in the pool in an idle state.

Values <= 0 are treated as 0.

Parameter
NameDescription
count int
Returns
TypeDescription
SessionPoolOptions &

max_idle_sessions() const

Return the maximum number of idle sessions to keep in the pool.

Returns
TypeDescription
int

set_action_on_exhaustion(ActionOnExhaustion)

Set whether to block or fail on pool exhaustion.

Parameter
NameDescription
action ActionOnExhaustion
Returns
TypeDescription
SessionPoolOptions &

action_on_exhaustion() const

Return the action to take (kBlock or kFail) when attempting to allocate a session when the pool is exhausted.

Returns
TypeDescription
ActionOnExhaustion

set_keep_alive_interval(std::chrono::seconds)

Set the interval at which we refresh sessions so they don't get collected by the backend GC.

The GC collects objects older than 60 minutes, so any duration below that (less some slack to allow the calls to be made to refresh the sessions) should suffice.

Parameter
NameDescription
interval std::chrono::seconds
Returns
TypeDescription
SessionPoolOptions &

keep_alive_interval() const

Return the interval at which we refresh sessions to prevent GC.

Returns
TypeDescription
std::chrono::seconds

set_labels(std::map< std::string, std::string >)

Set the labels used when creating sessions within the pool.

  • Label keys must match [a-z]([-a-z0-9]{0,61}[a-z0-9])?.
  • Label values must match ([a-z]([-a-z0-9]{0,61}[a-z0-9])?)?.
  • The maximum number of labels is 64.
Parameter
NameDescription
labels std::map< std::string, std::string >
Returns
TypeDescription
SessionPoolOptions &

labels() const

Return the labels used when creating sessions within the pool.

Returns
TypeDescription
std::map< std::string, std::string > const &