10 processes, but only 5 or 8 processes replying to the caller. Why?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

10 processes, but only 5 or 8 processes replying to the caller. Why?

I Gusti Ngurah Oka Prinarjaya
Hi,

I have following code

https://pastebin.com/rQE1t1XA (order_manager.erl)

and 

https://pastebin.com/ruGvGEKS (example_worker.erl)

order_manager:create_order(poolnameany)  will create 10 worker processes, under supervisor named poolnameany. Each worker processes is spawn of example_worker.erl

order_manager:cast_order(poolnameany) will sending / distributing message to all of worker processes in paralalel. So all 10 worker processes will receive same message content.

In example_worker.erl have following lines of code part:

%% example_worker.erl
-define(SLEEP_RANDOM, [3000, 4000, 5000, 6000, 2000]).

pick_random_sleep() ->
  Res = lists:nth(rand:uniform(5), ?SLEEP_RANDOM),
  Res.
...
...
...
handle_call({receive_initial_order, Ref, InitialOrders}, _From, State) ->
  io:format("~p is receiving: ~p~n", [self(), InitialOrders]),
  timer:sleep(pick_random_sleep()),
  {reply, {ok, self(), Ref}, State#state{offset=3}};


My problem is, i am not able to get reply completely from all 10 worker processes. Why?
I always only get 5 or 8 reply from 5 or 8 worker processes. 8 often.

And, this is the handler to receive reply from each worker processes

buzz(_N, 11, _PoolName, _InitialOrders) ->
  ok;

buzz(N, Incr, PoolName, InitialOrders) ->
  spawn(fun() ->
    poolboy:transaction(
      PoolName,
      fun(Worker) ->
        Ref = make_ref(),
        {ok, WorkerPid, Ref} = gen_server:call(Worker, {receive_initial_order, Ref, InitialOrders}),
        io:format("Reply: [WorkerPid: ~p], [Ref: ~p]~n", [WorkerPid, Ref])
      end
    )
  end),
  buzz(N, Incr+1, PoolName, InitialOrders).


Screen Shot 2019-07-01 at 10.02.02.png


Eshell V10.2  (abort with ^G)

1> ===> The rebar3 shell is a development tool; to deploy applications in production, consider using releases (http://www.rebar3.org/docs/releases)

===> Booted sasl

===> Booted wx

===> Booted observer

===> Booted dist_procs_je_asane

 

1> order_manager:create_order(balihome).

ok

2> order_manager:cast_order(balihome).

<0.183.0> is receiving: [<<"Satu">>,<<"Dua">>,<<"Tiga">>]

<0.182.0> is receiving: [<<"Satu">>,<<"Dua">>,<<"Tiga">>]

<0.181.0> is receiving: [<<"Satu">>,<<"Dua">>,<<"Tiga">>]

<0.180.0> is receiving: [<<"Satu">>,<<"Dua">>,<<"Tiga">>]

<0.179.0> is receiving: [<<"Satu">>,<<"Dua">>,<<"Tiga">>]

<0.178.0> is receiving: [<<"Satu">>,<<"Dua">>,<<"Tiga">>]

<0.177.0> is receiving: [<<"Satu">>,<<"Dua">>,<<"Tiga">>]

ok

<0.176.0> is receiving: [<<"Satu">>,<<"Dua">>,<<"Tiga">>]

3> <0.175.0> is receiving: [<<"Satu">>,<<"Dua">>,<<"Tiga">>]

<0.174.0> is receiving: [<<"Satu">>,<<"Dua">>,<<"Tiga">>]

Reply: [WorkerPid: <0.180.0>], [Ref: #Ref<0.2480760321.1800142849.332>]

Reply: [WorkerPid: <0.183.0>], [Ref: #Ref<0.2480760321.1800142849.326>]

Reply: [WorkerPid: <0.182.0>], [Ref: #Ref<0.2480760321.1800142849.328>]

Reply: [WorkerPid: <0.176.0>], [Ref: #Ref<0.2480760321.1800142849.340>]

Reply: [WorkerPid: <0.181.0>], [Ref: #Ref<0.2480760321.1800142849.330>]

Reply: [WorkerPid: <0.179.0>], [Ref: #Ref<0.2480760321.1800142849.334>]

Reply: [WorkerPid: <0.175.0>], [Ref: #Ref<0.2480760321.1800142849.342>]

Reply: [WorkerPid: <0.178.0>], [Ref: #Ref<0.2480760321.1800142849.336>]



Please enlightenment 

Thank you






_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: 10 processes, but only 5 or 8 processes replying to the caller. Why?

Nevar
gen_server:call has default timeout = 5000. Your spawned process in buzz function get from gen_server:call timeout error and than exit with bad match.
As it not linked or supervised, an error message is not printed.
 
01.07.2019, 09:04, "I Gusti Ngurah Oka Prinarjaya" <[hidden email]>:
Hi,
 
I have following code
 
https://pastebin.com/rQE1t1XA (order_manager.erl)

and 
 
https://pastebin.com/ruGvGEKS (example_worker.erl)
 
order_manager:create_order(poolnameany)  will create 10 worker processes, under supervisor named poolnameany. Each worker processes is spawn of example_worker.erl
 
order_manager:cast_order(poolnameany) will sending / distributing message to all of worker processes in paralalel. So all 10 worker processes will receive same message content.
 
In example_worker.erl have following lines of code part:

%% example_worker.erl
-define(SLEEP_RANDOM, [3000, 4000, 5000, 6000, 2000]).

pick_random_sleep() ->
  Res = lists:nth(rand:uniform(5), ?SLEEP_RANDOM),
  Res.
...
...
...
handle_call({receive_initial_order, Ref, InitialOrders}, _From, State) ->
  io:format("~p is receiving: ~p~n", [self(), InitialOrders]),
  timer:sleep(pick_random_sleep()),
  {reply, {ok, self(), Ref}, State#state{offset=3}};
 
My problem is, i am not able to get reply completely from all 10 worker processes. Why?
I always only get 5 or 8 reply from 5 or 8 worker processes. 8 often.
 
And, this is the handler to receive reply from each worker processes
 
buzz(_N, 11, _PoolName, _InitialOrders) ->
  ok;

buzz(N, Incr, PoolName, InitialOrders) ->
  spawn(fun() ->
    poolboy:transaction(
      PoolName,
      fun(Worker) ->
        Ref = make_ref(),
        {ok, WorkerPid, Ref} = gen_server:call(Worker, {receive_initial_order, Ref, InitialOrders}),
        io:format("Reply: [WorkerPid: ~p], [Ref: ~p]~n", [WorkerPid, Ref])
      end
    )
  end),
  buzz(N, Incr+1, PoolName, InitialOrders).
 
Screen Shot 2019-07-01 at 10.02.02.png
 
 

Eshell V10.2  (abort with ^G)

1> ===> The rebar3 shell is a development tool; to deploy applications in production, consider using releases (http://www.rebar3.org/docs/releases)

===> Booted sasl

===> Booted wx

===> Booted observer

===> Booted dist_procs_je_asane

 

1> order_manager:create_order(balihome).

ok

2> order_manager:cast_order(balihome).

<0.183.0> is receiving: [<<"Satu">>,<<"Dua">>,<<"Tiga">>]

<0.182.0> is receiving: [<<"Satu">>,<<"Dua">>,<<"Tiga">>]

<0.181.0> is receiving: [<<"Satu">>,<<"Dua">>,<<"Tiga">>]

<0.180.0> is receiving: [<<"Satu">>,<<"Dua">>,<<"Tiga">>]

<0.179.0> is receiving: [<<"Satu">>,<<"Dua">>,<<"Tiga">>]

<0.178.0> is receiving: [<<"Satu">>,<<"Dua">>,<<"Tiga">>]

<0.177.0> is receiving: [<<"Satu">>,<<"Dua">>,<<"Tiga">>]

ok

<0.176.0> is receiving: [<<"Satu">>,<<"Dua">>,<<"Tiga">>]

3> <0.175.0> is receiving: [<<"Satu">>,<<"Dua">>,<<"Tiga">>]

<0.174.0> is receiving: [<<"Satu">>,<<"Dua">>,<<"Tiga">>]

Reply: [WorkerPid: <0.180.0>], [Ref: #Ref<0.2480760321.1800142849.332>]

Reply: [WorkerPid: <0.183.0>], [Ref: #Ref<0.2480760321.1800142849.326>]

Reply: [WorkerPid: <0.182.0>], [Ref: #Ref<0.2480760321.1800142849.328>]

Reply: [WorkerPid: <0.176.0>], [Ref: #Ref<0.2480760321.1800142849.340>]

Reply: [WorkerPid: <0.181.0>], [Ref: #Ref<0.2480760321.1800142849.330>]

Reply: [WorkerPid: <0.179.0>], [Ref: #Ref<0.2480760321.1800142849.334>]

Reply: [WorkerPid: <0.175.0>], [Ref: #Ref<0.2480760321.1800142849.342>]

Reply: [WorkerPid: <0.178.0>], [Ref: #Ref<0.2480760321.1800142849.336>]

 

 
Please enlightenment 
 
Thank you
 
 
 
 
 
,

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: 10 processes, but only 5 or 8 processes replying to the caller. Why?

I Gusti Ngurah Oka Prinarjaya
Hi,

Thank you very much :)
Thanks for the clue, then it works after increasing the timeout through 3rd parameter of gen_server:call()




Pada tanggal Sen, 1 Jul 2019 pukul 12.09 Slava Yurin <[hidden email]> menulis:
gen_server:call has default timeout = 5000. Your spawned process in buzz function get from gen_server:call timeout error and than exit with bad match.
As it not linked or supervised, an error message is not printed.
 
01.07.2019, 09:04, "I Gusti Ngurah Oka Prinarjaya" <[hidden email]>:
Hi,
 
I have following code
 
https://pastebin.com/rQE1t1XA (order_manager.erl)

and 
 
https://pastebin.com/ruGvGEKS (example_worker.erl)
 
order_manager:create_order(poolnameany)  will create 10 worker processes, under supervisor named poolnameany. Each worker processes is spawn of example_worker.erl
 
order_manager:cast_order(poolnameany) will sending / distributing message to all of worker processes in paralalel. So all 10 worker processes will receive same message content.
 
In example_worker.erl have following lines of code part:

%% example_worker.erl
-define(SLEEP_RANDOM, [3000, 4000, 5000, 6000, 2000]).

pick_random_sleep() ->
  Res = lists:nth(rand:uniform(5), ?SLEEP_RANDOM),
  Res.
...
...
...
handle_call({receive_initial_order, Ref, InitialOrders}, _From, State) ->
  io:format("~p is receiving: ~p~n", [self(), InitialOrders]),
  timer:sleep(pick_random_sleep()),
  {reply, {ok, self(), Ref}, State#state{offset=3}};
 
My problem is, i am not able to get reply completely from all 10 worker processes. Why?
I always only get 5 or 8 reply from 5 or 8 worker processes. 8 often.
 
And, this is the handler to receive reply from each worker processes
 
buzz(_N, 11, _PoolName, _InitialOrders) ->
  ok;

buzz(N, Incr, PoolName, InitialOrders) ->
  spawn(fun() ->
    poolboy:transaction(
      PoolName,
      fun(Worker) ->
        Ref = make_ref(),
        {ok, WorkerPid, Ref} = gen_server:call(Worker, {receive_initial_order, Ref, InitialOrders}),
        io:format("Reply: [WorkerPid: ~p], [Ref: ~p]~n", [WorkerPid, Ref])
      end
    )
  end),
  buzz(N, Incr+1, PoolName, InitialOrders).
 
Screen Shot 2019-07-01 at 10.02.02.png
 
 

Eshell V10.2  (abort with ^G)

1> ===> The rebar3 shell is a development tool; to deploy applications in production, consider using releases (http://www.rebar3.org/docs/releases)

===> Booted sasl

===> Booted wx

===> Booted observer

===> Booted dist_procs_je_asane

 

1> order_manager:create_order(balihome).

ok

2> order_manager:cast_order(balihome).

<0.183.0> is receiving: [<<"Satu">>,<<"Dua">>,<<"Tiga">>]

<0.182.0> is receiving: [<<"Satu">>,<<"Dua">>,<<"Tiga">>]

<0.181.0> is receiving: [<<"Satu">>,<<"Dua">>,<<"Tiga">>]

<0.180.0> is receiving: [<<"Satu">>,<<"Dua">>,<<"Tiga">>]

<0.179.0> is receiving: [<<"Satu">>,<<"Dua">>,<<"Tiga">>]

<0.178.0> is receiving: [<<"Satu">>,<<"Dua">>,<<"Tiga">>]

<0.177.0> is receiving: [<<"Satu">>,<<"Dua">>,<<"Tiga">>]

ok

<0.176.0> is receiving: [<<"Satu">>,<<"Dua">>,<<"Tiga">>]

3> <0.175.0> is receiving: [<<"Satu">>,<<"Dua">>,<<"Tiga">>]

<0.174.0> is receiving: [<<"Satu">>,<<"Dua">>,<<"Tiga">>]

Reply: [WorkerPid: <0.180.0>], [Ref: #Ref<0.2480760321.1800142849.332>]

Reply: [WorkerPid: <0.183.0>], [Ref: #Ref<0.2480760321.1800142849.326>]

Reply: [WorkerPid: <0.182.0>], [Ref: #Ref<0.2480760321.1800142849.328>]

Reply: [WorkerPid: <0.176.0>], [Ref: #Ref<0.2480760321.1800142849.340>]

Reply: [WorkerPid: <0.181.0>], [Ref: #Ref<0.2480760321.1800142849.330>]

Reply: [WorkerPid: <0.179.0>], [Ref: #Ref<0.2480760321.1800142849.334>]

Reply: [WorkerPid: <0.175.0>], [Ref: #Ref<0.2480760321.1800142849.342>]

Reply: [WorkerPid: <0.178.0>], [Ref: #Ref<0.2480760321.1800142849.336>]

 

 
Please enlightenment 
 
Thank you
 
 
 
 
 
,

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions