[erlang-questions] 10 processes, but only 5 or 8 processes replying to the caller. Why?

I Gusti Ngurah Oka Prinarjaya okaprinarjaya@REDACTED
Mon Jul 1 04:03:23 CEST 2019


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

[image: 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20190701/f2648ab9/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2019-07-01 at 10.02.02.png
Type: image/png
Size: 175413 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20190701/f2648ab9/attachment.png>


More information about the erlang-questions mailing list