From 7dfbde316104d06f8585e86c7fea284ad136a566 Mon Sep 17 00:00:00 2001 From: Nathan Lasseter Date: Thu, 27 Jan 2011 22:35:34 +0000 Subject: Wrote simple readme --- README | 19 +++++++++++++++++++ erlbal.erl | 5 ++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/README b/README index e69de29..5b4d3cd 100644 --- a/README +++ b/README @@ -0,0 +1,19 @@ +erlbal is an erlang load balancer. + + +start_bal/0 spawns a balancer. +stop_bal/1 takes a balancer and kills all of its servers and then kills the balancer. +list_servers/1 takes a balancer and returns a list of the servers it balances over. + +start_server/2 takes a balancer and a function and spawns a server to serve the function. +stop_server/2 takes a balancer and a server PID and stops the server and removes it from the balancer. + +make_request/2 takes a balancer and an argument and returns the response from the server. + + +The balancer round robins requests between erlang processes. +When it receives a request, it forwards it on to the next server in the round robin. +The server then runs the function with the argument passed to it and returns a response to the balancer. +The balancer forwards the response back to the requestor. + +The function arg could be anything, so you can pass multiple args in a tuple or list, etc. diff --git a/erlbal.erl b/erlbal.erl index e24dd26..decfc42 100644 --- a/erlbal.erl +++ b/erlbal.erl @@ -27,8 +27,7 @@ start_bal() -> spawn(fun() -> bal_loop([], 1) end). stop_bal(Balancer) -> - Balancer ! die, - unregister(Balancer). + Balancer ! die. bal_loop(Serverlist, Nextserver) -> receive @@ -48,7 +47,7 @@ bal_loop(Serverlist, Nextserver) -> NS > SLL -> bal_loop(Serverlist, 1); true -> - bal_loop(Serverlist, Nextserver+1) + bal_loop(Serverlist, NS) end; {response, To, Ret} -> To ! Ret, -- cgit v1.2.1