gRPC client and Session Pool

The plugin uses the Spanner gRPC API. When interacting with Spanner over gRPC a session pool needs to be maintained. Each spanner transaction, read or write, needs to be done in the context of a session.

The default session pool size is 5, which limits the number of concurrent reads and writes to Spanner. This value will need to be increased if you use-case has a large number of concurrent writes or reads.

Sessions are kept alive indefinitely. Support for dynamic resizing is tracked in issue 13.

The maximum value is 100, set by Spanner. Future versions of the plugin may create multiple gRPC clients to allow more than 100 sessions at a time.

Session configuration

source  session-pool {
    # the max number of sessions to create when connecting to spanner.
    # currently all of these sessions are created eagerly and kept alive.
    # called 'max-size' as future versions will likely have a dynamic
    # session pool
    max-size = 20

    # the max number of outstanding requests for sessions when the pool is
    # fully utilized
    max-outstanding-requests = 1000

    # How often to retry the batch create sessions on start up and also
    # how often to retry of a single session create in the event
    # of a NOT_FOUND being returned during keep alive. NOT_FOUND indicates
    # that the spanner server has deleted the session.
    retry-create-interval = 2s

    # If the pool encounters an unexpected error, how long to backoff for before
    # re-creating the pool from scratch. For expected errors such as the intitial
    # batch session creation set other specific intervals
    restart-min-backoff = 1s
    restart-max-backoff = 10s

    # How often to send a dummy query for each session to keep it alive
    # Spanner drops sessions after 60 minutes
    keep-alive-interval = 25 minutes

    # Internal between each log of stats
    # set to off to disable
    stats-interval = off
    # Stats logger to use, set this logger to DEBUG in your configuration
    # to see the stats logging
    stats-logger = "akka.persistence.spanner.SessionPool.stats"

    # Keep lower than coordinated shutdown stage timeout
    # if sessions aren't returned within this timeout then they
    # are deleted meaning in progress queries will fail
    shutdown-timeout = 3s

  # set to false for running with the spanner emulator
  use-auth = true

  # Fail a request if a session cannot be acquired within this timeout
  session-acquisition-timeout = 5 s

  # If a write fails retry at most this many times
  # also time capped within the retry interval. Note that the timeout is in concert with
  # the akka persistence circuit breaker call timeout
  max-write-retries = 3
  max-write-retry-timeout = 10s


gRPC client configuration

sourceakka.grpc.client.spanner-client {
  host =
  port = 443

See the gRPC documentation for configuring the client.


You can override the client’s gRPCssl-config section in akka.grpc.client.spanner-client. The Lightbend SSL Config’s documention for more details.

Found an error in this documentation? The source code for this page can be found here. Please feel free to edit and contribute a pull request.