Erlang/OTP Forums

Author Message

<  Erlang questions mailing list  ~  noob gen_leader question

Guest
Posted: Mon Apr 07, 2008 6:57 pm Reply with quote
Guest
I have looked at gdict example.
uwiger
Posted: Mon Apr 07, 2008 8:48 pm Reply with quote
User Joined: 03 Jul 2006 Posts: 604 Location: Sweden
db skrev:
> I have looked at gdict example. Storing values into global dict goes to
> the leader and lookup is done by workers on the local gen_leader instance.
>
> It seems gen_leader works by having worker pull task rather than master
> push task. Am I right?

No, the leader pushes the whole dictionary when elected, and
then each update function, as all updates go through the
leader process.

So, for example (expanding the macro definition):

-define(store(Dict,Expr,Legend),
gen_leader:leader_call(Dict, {store, fun(D) ->
Expr
end})).

-define(lookup(Dict, Expr, Legend),
gen_leader:call(Dict, {lookup, fun(D) ->
Expr
end})).

%% dict functions that modify state:
append(Key, Value, Dict) ->
gen_leader:leader_call(
Dict, {store, fun(D) ->
dict:append(Key,Value,D)

end})).

then, in the callback module:

handle_leader_call({store,F}, _From, Dict, _E) ->
NewDict = F(Dict),
{reply, ok, {store, F}, NewDict};
^^^^ <- this is the push


and here's where the workers receive it:

from_leader({store,F}, Dict, _E) ->
NewDict = F(Dict),
{ok, NewDict}.



BR,
Ulf W
_______________________________________________
erlang-questions mailing list
erlang-questions@erlang.org
http://www.erlang.org/mailman/listinfo/erlang-questions
Post recived from mailinglist
View user's profile Send private message Visit poster's website
Guest
Posted: Sun Apr 13, 2008 1:03 pm Reply with quote
Guest
Does worker instance of gen_leader spawn separate processes to perform a task concurrently like in pool module?


On Mon, Apr 7, 2008 at 4:46 PM, Ulf Wiger (TN/EAB) <ulf.wiger@ericsson.com (ulf.wiger@ericsson.com)> wrote:
Quote:
db skrev:
Quote:
I have looked at gdict example.
uwiger
Posted: Sun Apr 13, 2008 7:59 pm Reply with quote
User Joined: 03 Jul 2006 Posts: 604 Location: Sweden
db skrev:
> Does worker instance of gen_leader spawn separate processes to perform a
> task concurrently like in pool module?

Not by default, no. If you want to spawn processes, you
can of course do that in the callbacks.

BR,
Ulf W
_______________________________________________
erlang-questions mailing list
erlang-questions@erlang.org
http://www.erlang.org/mailman/listinfo/erlang-questions
Post recived from mailinglist
View user's profile Send private message Visit poster's website
Guest
Posted: Fri Apr 18, 2008 4:23 am Reply with quote
Guest
My erlang nodes are setup to connect to each other automatically.
Patched version of gen_leader states that it was modified to start
only on local mode and user has to trigger the election mode. This
means each instance of gen_leader is myopic and is contained within a
single node that it is running on. How does a user trigger the
election mode so that all other the instances of gen_leader know the
existence of each other?

It starts off with global mode:
elected([], {election,<0.64.0>,global,aname,a@mybox,

Then it goes into local mode:
initial call: gen:init_it(gen_leader,<0.62.0>,self,
{local,aname},

On Sun, Apr 13, 2008 at 3:57 PM, Ulf Wiger (TN/EAB)
<ulf.wiger@ericsson.com> wrote:
> db skrev:
>
>
> > Does worker instance of gen_leader spawn separate processes to perform a task concurrently like in pool module?
> >
>
> Not by default, no. If you want to spawn processes, you
> can of course do that in the callbacks.
>
> BR,
> Ulf W
>



--
rk

That which we persist in doing becomes easier for us to do; not that
the nature of the thing itself is changed, but that our power to do is
increased.
-Ralph Waldo Emerson
_______________________________________________
erlang-questions mailing list
erlang-questions@erlang.org
http://www.erlang.org/mailman/listinfo/erlang-questions
Post recived from mailinglist
uffe
Posted: Fri Apr 18, 2008 6:54 am Reply with quote
User Joined: 02 Mar 2005 Posts: 365 Location: Sweden
The local-only mode was a way to allow the process to start before
the distribution was activated. In gproc, I allowed only local
registrations until a leader was elected, and I provided no function
for going back to local mode, once activated.

BR,
Ulf W

2008/4/18, db <masterofquestions@gmail.com>:
> My erlang nodes are setup to connect to each other automatically.
> Patched version of gen_leader states that it was modified to start
> only on local mode and user has to trigger the election mode. This
> means each instance of gen_leader is myopic and is contained within a
> single node that it is running on. How does a user trigger the
> election mode so that all other the instances of gen_leader know the
> existence of each other?
>
> It starts off with global mode:
> elected([], {election,<0.64.0>,global,aname,a@mybox,
>
> Then it goes into local mode:
> initial call: gen:init_it(gen_leader,<0.62.0>,self,
> {local,aname},
>
> On Sun, Apr 13, 2008 at 3:57 PM, Ulf Wiger (TN/EAB)
> <ulf.wiger@ericsson.com> wrote:
> > db skrev:
> >
> >
> > > Does worker instance of gen_leader spawn separate processes to perform a
> task concurrently like in pool module?
> > >
> >
> > Not by default, no. If you want to spawn processes, you
> > can of course do that in the callbacks.
> >
> > BR,
> > Ulf W
> >
>
>
>
> --
> rk
>
> That which we persist in doing becomes easier for us to do; not that
> the nature of the thing itself is changed, but that our power to do is
> increased.
> -Ralph Waldo Emerson
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@erlang.org
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
_______________________________________________
erlang-questions mailing list
erlang-questions@erlang.org
http://www.erlang.org/mailman/listinfo/erlang-questions
Post recived from mailinglist
View user's profile Send private message Visit poster's website
Guest
Posted: Fri Apr 18, 2008 5:15 pm Reply with quote
Guest
I reran the gdict example and election record shows b@mybox as down.
Even though this is not the case, but simply b@mybox is not the
current leader. There is no distinction made between node being down
and nodes that aren't elected leader in actual election record/tuple.

Also, what is buffered field in the election record definition?

On Fri, Apr 18, 2008 at 2:52 AM, Ulf Wiger <ulf@wiger.net> wrote:
> The local-only mode was a way to allow the process to start before
> the distribution was activated. In gproc, I allowed only local
> registrations until a leader was elected, and I provided no function
> for going back to local mode, once activated.
>
> BR,
> Ulf W
>
Thank you,
--
rk

That which we persist in doing becomes easier for us to do; not that
the nature of the thing itself is changed, but that our power to do is
increased.
-Ralph Waldo Emerson
_______________________________________________
erlang-questions mailing list
erlang-questions@erlang.org
http://www.erlang.org/mailman/listinfo/erlang-questions
Post recived from mailinglist
Guest
Posted: Fri Apr 18, 2008 6:51 pm Reply with quote
Guest
Here is the module used to run gdict and it's corresponding output:

-module(gen_leader_for_dummies).
-export([main/0]).

-define(DUMP(X), io:format("~p:~p - ~p = ~p~n", [?MODULE, ?
LINE, ??X, X])).

main() ->

?DUMP(node()),
?DUMP(nodes()),

%CandidateNodes and WorkerNodes are disjoint set of nodes
CandidateNodes = [a@mybox,b@mybox],
WorkerNodes = [wa@mybox,wb@mybox],

?DUMP(CandidateNodes),
?DUMP(WorkerNodes),
{ok, D} = gdict:new(dummy, CandidateNodes, WorkerNodes),
?DUMP(D),
?DUMP(gdict:append(a, 1, D)),
?DUMP(gdict:append(b, 2, D)),
?DUMP(gdict:append(c, 3, D)),
?DUMP(gdict:find(a, D)),
?DUMP(gdict:find(b, D)),
?DUMP(gdict:find(c, D)).

(a@mybox)1> gen_leader_for_dummies:main().
gen_leader_for_dummies:9 - "node ( )" = a@mybox
gen_leader_for_dummies:10 - "nodes ( )" = [wb@mybox,wa@mybox,b@mybox]
gen_leader_for_dummies:15 - "CandidateNodes" = [a@mybox,b@mybox]
gen_leader_for_dummies:16 - "WorkerNodes" = [wa@mybox,wb@mybox]
init({dict,0,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
{{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]}}})
gen_leader_for_dummies:18 - "D" = <0.72.0>
elected([], {election,<0.72.0>,global,dummy,a@mybox,
[a@mybox,b@mybox],
[wa@mybox,wb@mybox],
[],
{[],1},
[b@mybox],
[{#Ref<0.0.0.197>,wb@mybox},{#Ref<0.0.0.196>,wa@mybox}],
[]})
gen_leader_for_dummies:19 - "gdict : append ( a , 1 , D )" = ok
gen_leader_for_dummies:20 - "gdict : append ( b , 2 , D )" = ok
gen_leader_for_dummies:21 - "gdict : append ( c , 3 , D )" = ok
gen_leader_for_dummies:22 - "gdict : find ( a , D )" = {ok,[1]}
gen_leader_for_dummies:23 - "gdict : find ( b , D )" = {ok,[2]}
gen_leader_for_dummies:24 - "gdict : find ( c , D )" = {ok,[3]}
ok


On Fri, Apr 18, 2008 at 1:13 PM, db <masterofquestions@gmail.com> wrote:
> I reran the gdict example and election record shows b@mybox as down.
> Even though this is not the case, but simply b@mybox is not the
> current leader. There is no distinction made between node being down
> and nodes that aren't elected leader in actual election record/tuple.
>
> Also, what is buffered field in the election record definition?
-
rk

That which we persist in doing becomes easier for us to do; not that
the nature of the thing itself is changed, but that our power to do is
increased.
-Ralph Waldo Emerson
_______________________________________________
erlang-questions mailing list
erlang-questions@erlang.org
http://www.erlang.org/mailman/listinfo/erlang-questions
Post recived from mailinglist
wuji
Posted: Sat Aug 11, 2012 2:34 am Reply with quote
User Joined: 10 Aug 2012 Posts: 654
than half a century, and a football team's worth of of Cheap Ralph Lauren Shirts of children and grandchildren."He died as he lived. He
hard until the end, stayed positive, thought only of others others replica Christian Louboutin others and constantly reminded everyone of how blessed his life
been. His ambitions were far reaching, but he never never discount designer *beep* never believed he had to leave this Happy Valley to
them. He was a man devoted to his family, family, [h4]designer replica *beep*[/h4] family, his university, his players and his community," Paterno's family
in a statement.While at Penn State's helm, Paterno, who was was [h2]replica designer bags for sale[/h2] was born in Brooklyn, N.Y., led the Nittany Lions to
undefeated seasons and two NCAA championships, had only five losing losing cheap Ralph Lauren Polo losing seasons, was inducted into the College Football Hall of
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum