sprotector (sbroker v1.1.2)
This modules provides utility functions for overload protection and/or short circuiting calls to a process. It is designed for use with sbroker and sregulator processes using the sprotector_pie_meter meter. However any OTP process can use this module to do load balancing using the via naming format if the process is registered with and updates the sprotector_server.
To use sprotector with via use names of the form {via, sprotector, {Broker, ask | ask_r}}. Where {Broker, ...} is a tuple containing pid() | atom() | {global, any()} | {via, module(), any()} | {atom(), node()}. The lookup will succeed if the approximate queue length is less than or equal to the minimum queue length or below the the maximum and the drop probability allows. Otherwise the call exits with reason drop.
Therefore when combining with sbetter use format: {via, sprotector, {{via, sbetter, {..., ask | ask_r}, ask | ask_r}}. So the load balancing lookup is resolved first and wrapped by sprotector.
It is not possible to locally look up the pid of a process with name {atom(), node()} if the node is not the local node. Therefore a registered name on another node is not supported for use with this module.
If a chosen process is not local the call may exit with {badnode, node()}.
sprotector_server the call may exit with {noprotector, pid()}. The sdropper_pie_meter will register with the server and update it using the PIE active queue management algorithm. However other methods can be used to register and update the sprotector_server. Registering with the sdropper_server must be done with sprotector_server:register/1 and not using start_link({via, sprotector, ...}, ...).See also: sprotector_pie_meter, sprotector_server.
Summary
Functions
ok if the message is sent otherwise exits.undefined.Types
process/0
-type process() :: pid() | atom() | {atom(), node()} | {global, term()} | {via, module(), term()}.
Functions
send(Process, Msg)
-spec send({Process, ask | ask_r}, Msg) -> ok when Process :: process(), Msg :: any().
ok if the message is sent otherwise exits.
whereis_name(_)
-spec whereis_name({Process, ask | ask_r}) -> Pid | undefined when Process :: process(), Pid :: pid().
undefined.