# Class SessionPoolOptions (3.7.0-rc)

3.7.0-rc 3.6.0 (latest) 3.5.0 3.4.0 3.3.0 3.2.0 2.48.0-rc 2.47.1 2.46.0 2.45.0 2.44.0 2.43.0 2.42.0 2.41.0 2.40.0 2.39.0 2.38.0 2.37.0 2.36.0 2.35.0 2.34.0 2.33.0 2.32.0 2.31.0 2.30.0 2.29.0 2.28.0 2.27.0 2.26.0 2.25.1 2.24.0 2.23.0 2.22.1 2.21.0 2.20.0 2.19.0 2.18.0 2.17.0 2.16.0 2.15.1 2.14.0 2.13.0 2.12.0 2.11.0 Controls the session pool maintained by a [`spanner::Client`](https://docs.cloud.google.com/cpp/docs/reference/spanner/latest/classgoogle_1_1cloud_1_1spanner_1_1Client).
Creating Cloud Spanner sessions is an expensive operation. The [recommended practice](https://cloud.google.com/spanner/docs/sessions) 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.

> [!NOTE]
> **Note:** If no sessions are available to perform an operation the client library blocks until new sessions are available (either released by other threads or allocated on-demand, depending on the active constraints). It is also possible to configure the client to fail a request when the session pool is exhausted.

> [!WARNING]
> **Deprecated:** Use [`Options`](https://docs.cloud.google.com/cpp/docs/reference/common/latest/classgoogle_1_1cloud_1_1Options.html) instead, and set (as needed) [`GrpcNumChannelsOption`](https://docs.cloud.google.com/cpp/docs/reference/common/latest/structgoogle_1_1cloud_1_1GrpcNumChannelsOption.html), [`SessionPoolMinSessionsOption`](https://docs.cloud.google.com/cpp/docs/reference/spanner/latest/structgoogle_1_1cloud_1_1spanner_1_1SessionPoolMinSessionsOption), [`SessionPoolMaxSessionsPerChannelOption`](https://docs.cloud.google.com/cpp/docs/reference/spanner/latest/structgoogle_1_1cloud_1_1spanner_1_1SessionPoolMaxSessionsPerChannelOption), [`SessionPoolMaxIdleSessionsOption`](https://docs.cloud.google.com/cpp/docs/reference/spanner/latest/structgoogle_1_1cloud_1_1spanner_1_1SessionPoolMaxIdleSessionsOption), [`SessionPoolActionOnExhaustionOption`](https://docs.cloud.google.com/cpp/docs/reference/spanner/latest/structgoogle_1_1cloud_1_1spanner_1_1SessionPoolActionOnExhaustionOption), [`SessionPoolKeepAliveIntervalOption`](https://docs.cloud.google.com/cpp/docs/reference/spanner/latest/structgoogle_1_1cloud_1_1spanner_1_1SessionPoolKeepAliveIntervalOption), or [`SessionPoolLabelsOption`](https://docs.cloud.google.com/cpp/docs/reference/spanner/latest/structgoogle_1_1cloud_1_1spanner_1_1SessionPoolLabelsOption).

## 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** ||
|---|---|
| **Name** | **Description** |
| `num_channels` | `int` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `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** ||
|---|---|
| **Name** | **Description** |
| `count` | `int` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `SessionPoolOptions &` |   |

### min_sessions() const

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

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `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** ||
|---|---|
| **Name** | **Description** |
| `count` | `int` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `SessionPoolOptions &` |   |

### max_sessions_per_channel() const

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

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `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** ||
|---|---|
| **Name** | **Description** |
| `count` | `int` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `SessionPoolOptions &` |   |

### max_idle_sessions() const

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

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `int` |   |

### set_action_on_exhaustion(ActionOnExhaustion)

Set whether to block or fail on pool exhaustion.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `action` | `ActionOnExhaustion` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `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** ||
|---|---|
| **Type** | **Description** |
| `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** ||
|---|---|
| **Name** | **Description** |
| `interval` | `std::chrono::seconds` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `SessionPoolOptions &` |   |

### keep_alive_interval() const

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

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `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** ||
|---|---|
| **Name** | **Description** |
| `labels` | `std::map< std::string, std::string >` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `SessionPoolOptions &` |   |

### labels() const

Return the labels used when creating sessions within the pool.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `std::map< std::string, std::string > const &` |   |