En esta página, se muestra cómo anular el tiempo de espera predeterminado y configura una política de reintentos con el backend bibliotecas cliente.
Las bibliotecas cliente usan la configuración predeterminada de políticas de reintento y tiempo de espera, definidos en los siguientes archivos de configuración.
- spanner_grpc_service_config.json
- spanner_admin_instance_grpc_service_config.json
- spanner_admin_database_grpc_service_config.json
En los archivos de configuración, el tiempo de espera predeterminado para las operaciones que tardan
de tiempo, como CreateSession
, es de 30 segundos. Las operaciones más largas, como
como consultas o lecturas,
tienen un tiempo de espera predeterminado de 3,600 segundos. Recomendamos usar
estos valores predeterminados. Sin embargo, puedes establecer un tiempo de espera personalizado o una política de reintentos en
la aplicación si es necesario.
Si decides cambiar el tiempo de espera, configúralo en la cantidad real de el tiempo en que la aplicación está configurada para esperar el resultado.
No configures una política de reintentos más agresiva que la predeterminada. porque demasiados reintentos pueden sobrecargar el backend y limitar las solicitudes.
Se define una política de reintentos en cada fragmento, con lo siguiente características:
- Duración de tiempo de espera inicial antes de reintentar la solicitud.
- Un retraso máximo.
- Un multiplicador para usar con el tiempo de espera anterior para calcular el siguiente hasta alcanzar el máximo.
- Un conjunto de códigos de error para operaciones de reintento.
En el siguiente ejemplo, se establece un tiempo de espera de 60 segundos para la operación determinada.
Si la operación tarda más de este tiempo de espera, la operación falla y muestra
DEADLINE_EXCEEDED
error.
Si la operación falla con un código de error UNAVAILABLE
, por ejemplo, si hay un problema transitorio de red, se vuelve a intentar la operación. El cliente
espera 500 ms antes de iniciar el primer reintento. Si el primer reintento
falla, el cliente espera 1.5 * 500 ms = 750 ms antes de iniciar el segundo
vuelve a intentarlo. Esta demora en los reintentos
aumenta hasta que la operación
tiene éxito o alcanza el retraso máximo de reintento de 16 segundos. La operación falla con un error DEADLINE_EXCEEDED
si el tiempo total que se dedica a intentar la operación supera el valor total de tiempo de espera de 60 segundos.