Bases: google.appengine.ext.remote_api.throttle.Error
An unregistered thread has accessed the throttled datastore stub.
Bases: object
A base class for upload rate throttling.
Transferring large number of entities, too quickly, could trigger quota limits and cause the transfer process to halt. In order to stay within the application’s quota, we throttle the data transfer to a specified limit (across all transfer threads).
This class tracks a moving average of some aspect of the transfer rate (bandwidth, records per second, http connections per second). It keeps two windows of counts of bytes transferred, on a per-thread basis. One block is the “current” block, and the other is the “prior” block. It will rotate the counts from current to prior when ROTATE_PERIOD has passed. Thus, the current block will represent from 0 seconds to ROTATE_PERIOD seconds of activity (determined by: time.time() - self.last_rotate). The prior block will always represent a full ROTATE_PERIOD.
Sleeping is performed just before a transfer of another block, and is based on the counts transferred before the next transfer. It really does not matter how much will be transferred, but only that for all the data transferred SO FAR that we have interspersed enough pauses to ensure the aggregate transfer rate is within the specified limit.
These counts are maintained on a per-thread basis, so we do not require any interlocks around incrementing the counts. There IS an interlock on the rotation of the counts because we do not want multiple threads to multiply-rotate the counts.
There are various race conditions in the computation and collection of these counts. We do not require precise values, but simply to keep the overall transfer within the bandwidth limits. If a given pause is a little short, or a little long, then the aggregate delays will be correct.
Add a count to the amount this thread has transferred.
Each time a thread transfers some data, it should call this method to note the amount sent. The counts may be rotated if sufficient time has passed since the last rotation.
Parametersthrottle_name – The name of the throttle to add to.
token_count – The number to add to the throttle counter.
Register this thread with the throttler.
Possibly sleep in order to limit the transfer rate.
Note that we sleep based on prior transfers rather than what we may be about to transfer. The next transfer could put us under/over and that will be rectified after that transfer. Net result is that the average transfer rate will remain within bounds. Spiky behavior or uneven rates among the threads could possibly bring the transfer rate above the requested limit for short durations.
Parametersthrottle_name – The name of the throttle to sleep on. If None or omitted, then sleep on all throttles.
Return the total transferred, and over what period.
Parametersthrottle_name – The name of the throttle to total.
ReturnsA tuple of the total count and running time for the given throttle name.
Bases: urllib2.BaseHandler
A urllib2 handler for http and https requests that adds to a throttle.
Add to bandwidth throttle for given request.
Parametersthrottle_name – The name of the bandwidth throttle to add to.
req – The request whose size will be added to the throttle.
Add to bandwidth throttle for given response.
Parametersthrottle_name – The name of the bandwidth throttle to add to.
res – The response whose size will be added to the throttle.
Process an HTTP request.
If the throttle is over quota, sleep first. Then add request size to throttle before returning it to be sent.
Parametersreq – A urllib2.Request object.
ReturnsThe request passed in.
Process an HTTP response.
The size of the response is added to the bandwidth throttle and the request throttle is incremented by one.
Parametersunused_req – The urllib2 request for this response.
res – A urllib2 response object.
The response passed in.
Process an HTTPS request.
If the throttle is over quota, sleep first. Then add request size to throttle before returning it to be sent.
Parametersreq – A urllib2.Request object.
ReturnsThe request passed in.
Process an HTTPS response.
The size of the response is added to the bandwidth throttle and the request throttle is incremented by one.
Parametersunused_req – The urllib2 request for this response.
res – A urllib2 response object.
The response passed in.
Install the given throttle for the remote datastore stub.
Parametersthrottle – A Throttle instance to limit datastore access rates
remote_datastore_stub – The datstore stub instance to throttle, for testing purposes.
Bases: google.appengine.tools.appengine_rpc.HttpRpcServer
Provides a simplified RPC-style interface for HTTP requests.
This RPC server uses a Throttle to prevent exceeding quotas.
Bases: object
A factory to produce ThrottledHttpRpcServer for a given throttle.
Bases: google.appengine.tools.appengine_rpc_httplib2.HttpRpcServerOAuth2
Bases: google.appengine.ext.remote_api.throttle.Error
A transfer was added for an unknown throttle name.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-04-04 UTC.