The RetryParams Class

RetryParams is provided by the App Engine client library for Cloud Storage contained in src/cloudstorage. This class lets you change default settings used to handle timeouts and retries.

Introduction

The App Engine client library for Cloud Storage uses default settings for handling timeouts and retries during attempts to contact Google Cloud Storage servers. This class allows you to change those settings, either on an application-wide basis, or for a specific invocation of a library function (copy2, delete, listbucket, open, stat). You need change only the specific setting you are interested in, as all other settings are retained unless explicitly overwritten. Each RetryParams instance is unique per thread and per request.

To change a default setting application-wide, you create a RetryParams object, specify whatever settings you wish to change, and supply this object to the cloudstorage.set_default_retry_params() function as follows:

my_default_retry_params = cloudstorage.RetryParams(initial_delay=0.2,
                                      max_delay=5.0,
                                      backoff_factor=2,
                                      max_retry_period=15)
cloudstorage.set_default_retry_params(my_default_retry_params)

To change default settings for a specific function invocation only, create a RetryParams object and supply it directly to the function in its retry_params parameter, as follows:

write_retry_params = cloudstorage.RetryParams(backoff_factor=1.1)
gcs_file = cloudstorage.open(filename,
                    'w',
                    content_type='text/plain',
                    options={'x-goog-meta-foo': 'foo',
                             'x-goog-meta-bar': 'bar'},
                    retry_params=write_retry_params)

This has no effect on the default settings used by the app or by other function invocations.

Instance properties

A RetryParams instance has the following properties:

initial_delay
The number of seconds to delay before a retry. Default is 0.1. Delay helps distribute load at the Google Cloud Storage server.
backoff_factor
The exponential back-off multiplier, used to determine optimal processing rate. Default is 2.0. For a description and recommendations for setting this value, see the Google Cloud Storage documentation on backoff.
max_delay
The maximum number of seconds to wait between retries. Default is 10.0.
min_retries
The minimum number of times to retry. Default is 3.
max_retries
The maximum number of times to retry. Set this value to 0 if you don't want any retries. Default is 6.
max_retry_period
The maximum number of seconds that can be spent on all retries of a given request. Default is 30.0. Retry stops when this period passed AND min_retries has been attempted.
urlfetch_timeout
The number of seconds to wait for UrlFetch to contact the Google Cloud Storage servers before returning a timeout error. By default, this is set to None, which means use the default UrlFetch deadline, which is five seconds. You can set this to any value up to a maximum of 60 seconds.