Module riak_core_throttle

Throttling for activities that can potentially overload resources.

Description

Throttling for activities that can potentially overload resources. Provides support for "throttling" (i.e. slowing down) calling processes that, when under heavy load, could potentially overload other resources. Activities are identified by a unique key so that different throttle values can be used for different activities.

The throttle for an activity can be set to a specific value with the set_throttle/2 function, or it can be set to a value based on the current "load" for the activity by using the set_limits/2 function to define a mapping from load factors to throttle values, and then periodically calling the set_throttle_by_load/2 function with the current load factor. Note that "load factor" is an abstract concept, the purpose of which is simply to represent numerically the amount of load that an activity is under and map that level of load to a particular throttle level. Examples of metrics that could be used for load factors include the size of the mailbox for a particular process, or the number of messages per second being sent to an external service such as Solr.

Data Types

activity_key()

activity_key() = atom()

app_name()

app_name() = atom()

limits()

limits() = [{load_factor(), throttle_time()}]

load_factor()

load_factor() = number() | atom() | tuple()

throttle_time()

throttle_time() = non_neg_integer()

Function Index

clear_limits/2Clears the limits for the activity identified by AppName and Key.
clear_throttle/2Clears the throttle for the activity identified by AppName and Key.
create_limits_translator_fun/2Returns a fun that used in Cuttlefish translations to translate from configuration items of the form: ConfigPrefix.throttle.tier1.LoadFactorMeasure to the list of tuples form expected by the set_limits/2 function in this module.
disable_throttle/2Disables the throttle for the activity identified by AppName and Key.
enable_throttle/2Enables the throttle for the activity identified by AppName and Key.
get_limits/2Returns the limits for the activity identified by AppName and Key if defined, otherwise returns undefined.
get_throttle/2
init/0Initialize the throttling subsystem.
init/4Initializes the throttle for the activity identified by AppName and Key using configuration values found in the application environment for AppName.
is_throttle_enabled/2Returns true if the throttle for the activity identified by AppName and Key is enabled, false otherwise.
set_limits/3Sets the limits for the activity identified by AppName and Key.
set_throttle/3Sets the throttle for the activity identified by AppName and Key to the specified Time.
set_throttle_by_load/3Sets the throttle for the activity identified by AppName and Key to a value determined by consulting the limits for the activity.
throttle/2Sleep for the number of milliseconds specified as the throttle time for the activity identified by AppName and Key (unless the throttle for the activity has been disabled with disable_throttle/1).

Function Details

clear_limits/2

clear_limits(AppName::app_name(), Key::activity_key()) -> ok

Clears the limits for the activity identified by AppName and Key.

clear_throttle/2

clear_throttle(AppName::app_name(), Key::activity_key()) -> ok

Clears the throttle for the activity identified by AppName and Key.

create_limits_translator_fun/2

create_limits_translator_fun(ConfigPrefix, LoadFactorMeasure) -> any()

Returns a fun that used in Cuttlefish translations to translate from configuration items of the form: ConfigPrefix.throttle.tier1.LoadFactorMeasure to the list of tuples form expected by the set_limits/2 function in this module. See riak_kv.schema and yokozuna.schema for example usages.

disable_throttle/2

disable_throttle(AppName::app_name(), Key::activity_key()) -> ok

Disables the throttle for the activity identified by AppName and Key.

enable_throttle/2

enable_throttle(AppName::app_name(), Key::activity_key()) -> ok

Enables the throttle for the activity identified by AppName and Key.

get_limits/2

get_limits(AppName::app_name(), Key::activity_key()) -> limits() | undefined

Returns the limits for the activity identified by AppName and Key if defined, otherwise returns undefined.

get_throttle/2

get_throttle(AppName::app_name(), Key::activity_key()) -> throttle_time() | undefined

init/0

init() -> ok

Initialize the throttling subsystem. Should be called just once during startup, although calling multiple times will not have any negative consequences.

init/4

init(AppName::app_name(), Key::activity_key(), X3::{LimitsKey::atom(), LimitsDefault::limits()}, X4::{EnabledKey::atom(), EnabledDefault::boolean()}) -> ok | {error, Reason::term()}

Initializes the throttle for the activity identified by AppName and Key using configuration values found in the application environment for AppName.

is_throttle_enabled/2

is_throttle_enabled(AppName::app_name(), Key::activity_key()) -> boolean()

Returns true if the throttle for the activity identified by AppName and Key is enabled, false otherwise.

set_limits/3

set_limits(AppName::app_name(), Key::activity_key(), Limits::limits()) -> ok | no_return()

Sets the limits for the activity identified by AppName and Key. Limits is a mapping from load factors to throttle values. Once this mapping has been established, the set_throttle_by_load/2 function can be used to set the throttle for the activity based on the current load factor.

All of the throttle values in the Limits list must be non-negative integers. Additionally, the Limits list must contain a tuple with the key -1. If either of these conditions does not hold, this function exits with an error.

See also: set_throttle_by_load/2.

set_throttle/3

set_throttle(AppName::app_name(), Key::activity_key(), Time::throttle_time()) -> ok

Sets the throttle for the activity identified by AppName and Key to the specified Time.

set_throttle_by_load/3

set_throttle_by_load(AppName::app_name(), Key::activity_key(), LoadFactor::load_factor()) -> throttle_time()

Sets the throttle for the activity identified by AppName and Key to a value determined by consulting the limits for the activity. The throttle value is the value associated with the largest load factor <= LoadFactor. Normally the LoadFactor will be a number representing the current level of load for the activity, but it is also allowed to pass an atom or a tuple as the LoadFactor. This can be used when a numeric value cannot be established, and results in using the throttle value for the largest load factor defined in the limits for the activity.

If there are no limits defined for the activity, exits with error({no_limits, Key}).

See also: set_limits/2.

throttle/2

throttle(AppName::app_name(), Key::activity_key()) -> throttle_time()

Sleep for the number of milliseconds specified as the throttle time for the activity identified by AppName and Key (unless the throttle for the activity has been disabled with disable_throttle/1). If there is no throttle value configured for Key, then exits with error({badkey, Key}).


Generated by EDoc