Now, suppose we are designing an application, consists of 2 Erlang Nodes. On Node A, will be very many processes, in the orders of thousands. These processes access resources on Node B by sending a message to a registered process on Node B.
At Node B, lets say you have a process started by executing the following function:
start_server()-> register(zeemq_server,spawn(?MODULE,server,[])),ok.On Node A, any process that wants to execute any function in a given module on Node B, uses the following piece of code:
server()-> receive {{CallerPid, Ref}, {Module, Func, Args}} -> Result = (catch erlang:apply(Module, Func, Args)), CallerPid ! {Ref, Result}, server(); _ -> server() end.
call(Node, Module, Func, Args)-> Ref = make_ref(), Me = self(), {zeemq_server,Node} ! {{Me, Ref}, {Module, Func, Args}}, receive {Ref, Result} -> Result after timer:minutes(3) -> error_logger:error_report(["Call to server took so long"]), {error,remote_call_failed} end.So assuming that Process
zeemq_server
on Node B, will never be down, and that the network connection between Node A and B is always up, please answer the following questions:Qn 1: Since there is only one receiving process on Node B, its mail box is most likely to be full , all the time. This is because, the processes are many on Node A and at a given interval, say, 2 seconds, every process at least ,makes a single call to the Node B server. In which ways, can the reception be made redundant on the Node B ? , e.g. Process Groups e.t.c. and explain (the concept) how this would replace the server side code above. Show what changes would happen on the Client side.
Qn 2: In a situation where there is only one receiver on Node B, is there a maximum number of messages allowable in the process mail box ? how would erlang respond , if a single process mail ox is flooded with too many messages ?
Qn 3: In what ways, using the very concept showed above, can i guarantee that every process which sends a request , gets back an answer as soon as possible before the timeout occurs ? Could converting the reception part on the Node B to a parallel operation help ? like this:
start_server()-> register(zeemq_server,spawn(?MODULE,server,[])),ok.The method showed above, may increase the instantaneous number of processes running on the Node B, and this may affect the service greatly due to memory. However, it looks good and makes the
server()-> receive {{CallerPid, Ref}, {Module, Func, Args}} -> spawn(?MODULE,child,[Ref,CallerPid,{Module, Func, Args}]), server(); _ -> server() end.
child(Ref,CallerPid,{Module, Func, Args})-> Result = (catch erlang:apply(Module, Func, Args)), CallerPid ! {Ref, Result}, ok.
server()
loop to return immediately to handle the next request. What is your take on this modification ? Lastly : Illustrate how you would implement a
Pool of receiver Threads
on Node B, yet appearing to be under one Name
as regards Node A. Such that, incoming messages are multiplexed amongst the receiver threads and the load shared within this group of processes. Keep the meaning of the problem the same.Thank you
Erlangers
!