Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Il backoff esponenziale è una strategia standard di gestione degli errori per le applicazioni di rete in cui un client riprova periodicamente una richiesta non riuscita con ritardi crescenti tra le richieste. I client devono utilizzare il backoff esponenziale per tutte le richieste a Memorystore per Redis che restituiscono errori di codice di risposta HTTP 5xx e 429.
È importante comprendere il funzionamento del backoff esponenziale se:
Creazione di applicazioni client che utilizzano direttamente l'API REST di Memorystore for Redis.
Se utilizzi la consoleGoogle Cloud , questa invia le richieste a Memorystore for Redis per tuo conto e gestisce eventuali ritardi necessari.
Algoritmo di esempio
Un algoritmo di backoff esponenziale riprova le richieste in modo esponenziale,
aumentando il tempo di attesa tra i tentativi fino a un tempo di backoff massimo. Un
esempio è:
Invia una richiesta a Memorystore for Redis.
Se la richiesta non va a buon fine, attendi 1 + random_number_milliseconds secondi e riprova.
Se la richiesta non va a buon fine, attendi 2 + random_number_milliseconds secondi e riprova.
Se la richiesta non va a buon fine, attendi 4 + random_number_milliseconds secondi e riprova.
E così via fino a un intervallo di maximum_backoff.
Continua ad attendere e riprovare fino al numero massimo di nuovi tentativi, ma
non aumentare il periodo di attesa tra i tentativi.
dove:
Il tempo di attesa è min(((2^n)+random_number_milliseconds), maximum_backoff),
con n incrementato di 1 per ogni iterazione (richiesta).
random_number_milliseconds è un numero casuale di millisecondi minore o uguale a 1000. In questo modo si evitano i casi in cui molti client vengono sincronizzati da qualche situazione e riprovano tutti contemporaneamente, inviando richieste in ondate sincronizzate. Il valore di random_number_milliseconds deve essere ricalcolato dopo ogni richiesta di nuovo tentativo.
maximum_backoff in genere è di 32 o 64 secondi. Il valore appropriato dipende dal caso d'uso.
Puoi continuare a riprovare una volta raggiunto il tempo maximum_backoff.
I tentativi successivi a questo punto non devono continuare ad aumentare il tempo di backoff. Ad esempio, se un client utilizza un tempo maximum_backoff di 64 secondi, dopo aver raggiunto questo valore può riprovare ogni 64 secondi. A un certo punto,
i client devono essere impediti di riprovare all'infinito.
Il backoff massimo e il numero massimo di tentativi utilizzati da un client dipendono dal caso d'uso e dalle condizioni di rete. Ad esempio, i client mobile di un'applicazione potrebbero dover riprovare più volte e per intervalli più lunghi rispetto ai client desktop della stessa applicazione.
Se le richieste di ripetizione non vanno a buon fine dopo aver superato il numero massimo di tentativi, segnala o registra un errore utilizzando uno dei metodi elencati nella sezione Ricevere assistenza.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-05 UTC."],[],[],null,["# Exponential backoff\n\n[Exponential backoff](https://en.wikipedia.org/wiki/Exponential_backoff) is a standard error handling\nstrategy for network applications in which a client periodically retries a\nfailed request with increasing delays between requests. Clients should use\nexponential backoff for all requests to Memorystore for Redis that return\nHTTP `5xx` and `429` response code errors.\n\nUnderstanding how exponential backoff works is important if you are:\n\n- Building client applications that use the Memorystore for Redis [REST API](/memorystore/docs/redis/reference/rest)\n directly.\n\n- Accessing Memorystore for Redis through a [client library](/memorystore/docs/redis/libraries).\n Note that some client libraries, such as the [Memorystore for Redis Client Library for Node.js](https://googleapis.dev/nodejs/redis/latest/index.html),\n have built-in exponential backoff.\n\nIf you are using the [Google Cloud console](https://console.cloud.google.com/), the console sends\nrequests to Memorystore for Redis on your behalf and handles any necessary\nbackoff.\n\nExample algorithm\n-----------------\n\nAn exponential backoff algorithm retries requests exponentially,\nincreasing the waiting time between retries up to a maximum backoff time. An\nexample is:\n\n1. Make a request to Memorystore for Redis.\n\n2. If the request fails, wait 1 + `random_number_milliseconds` seconds and retry\n the request.\n\n3. If the request fails, wait 2 + `random_number_milliseconds` seconds and retry\n the request.\n\n4. If the request fails, wait 4 + `random_number_milliseconds` seconds and retry\n the request.\n\n5. And so on, up to a `maximum_backoff` time.\n\n6. Continue waiting and retrying up to some maximum number of retries, but\n do not increase the wait period between retries.\n\nwhere:\n\n- The wait time is min(((2\\^`n`)+`random_number_milliseconds`), `maximum_backoff`),\n with `n` incremented by 1 for each iteration (request).\n\n- `random_number_milliseconds` is a random number of milliseconds less than or\n equal to 1000. This helps to avoid cases where many clients get synchronized by\n some situation and all retry at once, sending requests in synchronized\n waves. The value of `random_number_milliseconds` should be recalculated after\n each retry request.\n\n- `maximum_backoff` is typically 32 or 64 seconds. The appropriate value\n depends on the use case.\n\nIt's okay to continue retrying once you reach the `maximum_backoff` time.\nRetries after this point do not need to continue increasing backoff time. For\nexample, if a client uses an `maximum_backoff` time of 64 seconds, then after\nreaching this value, the client can retry every 64 seconds. At some point,\nclients should be prevented from retrying infinitely.\n\nThe maximum backoff and maximum number of retries that a client uses\ndepends on the use case and network conditions. For example, mobile\nclients of an application may need to retry more times and for longer intervals\nwhen compared to desktop clients of the same application.\n\nIf the retry requests fail after exceeding the maximum number of retries, report\nor log an error using one of the methods listed under [Getting support](/memorystore/docs/redis/getting-support)."]]