throttle¶
-
class
naz.throttle.
BaseThrottleHandler
[source]¶ Bases:
abc.ABC
This is the interface that must be implemented to satisfy naz’s throttle handling. User implementations should inherit this class and implement the
throttled
,not_throttled
,allow_request
andthrottle_delay
methods with the type signatures shown.When an SMPP client exceeds it’s rate limit, or when the SMSC is under load or for whatever reason; The SMSC may decide to start throtlling requests from that particular client. When it does so, it replies to the client with a throttling status. Under such conditions, it is important for the client to start rate limiting itself. The way naz implements this self imposed self-regulation is via Throttle Handlers.
The methods in this class are also called when the SMSC is under load and is responding with `ESME_RMSGQFUL`(message queue full) responses
-
abstract async
allow_request
()[source]¶ this method will be called by naz just before sending a request to SMSC. The response from this method will determine wether naz will send the request or not.
- Return type
bool
-
abstract async
not_throttled
()[source]¶ this method will be called by naz everytime we get any response from SMSC that is not a throttling response.
- Return type
None
-
abstract async
throttle_delay
()[source]¶ if the last
allow_request
method call returned False(thus denying sending a request), naz will call the throttle_delay method to determine how long in seconds to wait before calling allow_request again.- Return type
float
-
abstract async
-
class
naz.throttle.
SimpleThrottleHandler
(sampling_period=180.0, sample_size=50.0, deny_request_at=1.0, throttle_wait=3.0, logger=None)[source]¶ Bases:
naz.throttle.BaseThrottleHandler
This is an implementation of BaseThrottleHandler.
It works by:
calculating the percentage of responses from the SMSC that are THROTTLING(or ESME_RMSGQFUL) responses.
if that percentage goes above
deny_request_at
percent AND total number of responses from SMSC is greater thansample_size
oversampling_period
secondsthen deny making anymore requests to SMSC
-
__init__
(sampling_period=180.0, sample_size=50.0, deny_request_at=1.0, throttle_wait=3.0, logger=None)[source]¶ - Parameters
sampling_period (
float
) – the duration in seconds over which we will calculate the percentage of throttled responses.sample_size (
float
) – the minimum number of responses we should have got from SMSC over :sampling_period duration to enable us make a decision.deny_request_at (
float
) – the percent of throtlled responses above which we will deny naz from sending more requests to SMSC.throttle_wait (
float
) – the time in seconds to wait before calling allow_request after the last allow_request that returned False.
- Return type
None
-
async
allow_request
()[source]¶ this method will be called by naz just before sending a request to SMSC. The response from this method will determine wether naz will send the request or not.
- Return type
bool
-
async
not_throttled
()[source]¶ this method will be called by naz everytime we get any response from SMSC that is not a throttling response.
- Return type
None
-
async
throttle_delay
()[source]¶ if the last
allow_request
method call returned False(thus denying sending a request), naz will call the throttle_delay method to determine how long in seconds to wait before calling allow_request again.- Return type
float