This page shows you how to override the default timeout configuration and configure a retry policy using the Spanner client libraries.
The client libraries use default timeout and retry policy settings which are defined in the following configuration files.
- spanner_grpc_service_config.json
- spanner_admin_instance_grpc_service_config.json
- spanner_admin_database_grpc_service_config.json
In the configuration files, the default timeout for operations that take a short
amount of time, such as CreateSession
, is 30 seconds. Longer operations, such
as queries or reads, have a default timeout of 3600 seconds. We recommend using
these defaults. However, you can set a custom timeout or retry policy in your
application if necessary.
If you decide to change the timeout, set it to the actual amount of time that the application is configured to wait for the result.
Don't configure a retry policy that is more aggressive than the default, because too many retries might overload the backend and throttle your requests.
A retry policy is defined in each snippet, with the following characteristics:
- The initial, or starting, wait time duration before retrying the request.
- A maximum delay.
- A multiplier to use with the previous wait time to calculate the next wait time, until the max is reached.
- A set of error codes for retry operations.
In the following sample, a timeout of 60 seconds is set for the given operation.
If the operation takes longer than this timeout, the operation fails with a
DEADLINE_EXCEEDED
error.
If the operation fails with an UNAVAILABLE
error code, for example, if there
is a transient network problem, the operation is retried. The client
waits for 500 ms before starting the first retry attempt. If the first retry
fails, the client waits for 1.5 * 500 ms = 750 ms before starting the second
retry. This retry delay continues to increase until the operation either
succeeds or reaches the maximum retry delay of 16 seconds. The operation fails
with a DEADLINE_EXCEEDED
error if the total time that is spent on trying the
operation exceeds the total timeout value of 60 seconds.