Module sbetter

This modules provides utility functions for load balancing using the best of two random choices.

References

See also: sbetter_meter, sbetter_server.

Description

This modules provides utility functions for load balancing using the best of two random choices. It is designed for use with sbroker and sregulator processes using the sbetter_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 sbetter_server.

To use sbetter with via use names of the form {via, sbetter, {{Broker, ...}, ask | ask_r}}. Where {Broker, ...} is a tuple containing pid() | atom() | {global, any()} | {via, module(), any()} | {atom(), node()}. The process with the small value/shortest sojourn time of two random processes for the ask (or ask_r) queue will be called. The sojourn time includes the message queue delay and the time spent waiting in the internal queue.

Comparing values/sojourn times requires ets lookups. However it is not required to carry out the lookups for every request to get well balanced queues. To only compare two random choices 20% of the time and use sscheduler the remaining 80% use scheduler_ask and scheduler_ask_r, or to only compare two random choices 20% of the time and choose a random process the reamining 80% use rand_ask and rand_ask_r. This ratio is chosen as the majority of the gain in choosing two random choices can be captured by giving 20% of requests a choice. See section 4.5 of the reference for more information.

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()}.

If a chosen process is not registered with the sbetter_server the call may exit with {nobetter, pid()}. The sbetter_meter will register with the server. However other methods can be used to register and update the sbetter_server. Registering with the sbetter_server must be done with sbetter_server:register/3 and not using start_link({via, sbetter, ...}, ...).

Data Types

method()

method() = ask | ask_r | scheduler_ask | scheduler_ask_r | rand_ask | rand_ask_r

Function Index

send/2Sends a message to a process from a tuple of processes using the best of two random choices for the queue (or possibly using the current scheduler id).
whereis_name/1Lookup a pid from a tuple of pids using the best of two random choices for the queue (or possibly using the current scheduler id).

Function Details

send/2

send(Name::{Processes, Method}, Msg) -> ok

Sends a message to a process from a tuple of processes using the best of two random choices for the queue (or possibly using the current scheduler id). Returns ok if a process could be chosen otherwise exits.

whereis_name/1

whereis_name(X1::{Processes, Method}) -> Process | undefined

Lookup a pid from a tuple of pids using the best of two random choices for the queue (or possibly using the current scheduler id). If no process is associated with the chosen process returns undefined.


Generated by EDoc, Sep 29 2016, 17:17:28.