Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spawning and monitoring multiple workers form one node #1

Open
shaleengarg opened this issue May 11, 2016 · 6 comments
Open

Spawning and monitoring multiple workers form one node #1

shaleengarg opened this issue May 11, 2016 · 6 comments

Comments

@shaleengarg
Copy link

In chapter 13, there is a question which asks us to write a program which can monitor multiple processes(workers). I have written a program which can monitor one process, but am not sure how to scale that for multiple processes.

@Stratus3D
Copy link
Owner

Hi @shaleengarg, do you know what number that exercise is? It looks like there are at least 6 exercises for chapter 13, and I have only completed 4 in this repository. If you let me know what number that exercise was I'll try to add that it as well.

@shaleengarg
Copy link
Author

shaleengarg commented May 11, 2016

Hi @Stratus3D . Its question 5 and 6 (Pg 209)

@shaleengarg
Copy link
Author

shaleengarg commented May 21, 2016

Hi @Stratus3D Please take a look at this code

%%Coded By shaleengarg
%%This module generates N processes on node and kills them
-module(processes).
-export([wait/0, master/1, sp/1]).

sp(N) ->
Max = erlang:system_info(process_limit),
io:format("Maximum allowed processes:pn",[Max]),
statistics(runtime),
statistics(wall_clock),
L = for(1, N, fun() -> spawn(fun() -> wait() end) end),
{, Time1} = statistics(runtime),
{
, Time2} = statistics(wall_clock),
lists:foreach(fun(Pid) -> Pid ! die end, L),
U1 = Time1 * 1000 / N,
U2 = Time2 * 1000 / N,
io:format("Process spawn time=~p (~p) microseconds from node: ~p ~n", [U1, U2, node()]).

%%list of the form [{Number of processes, Node}...]
master([]) -> [];

master(List) ->
[H|T] = List,
{Number, Node} = H,
subordinate(Number, Node),
io:format("Spawned a subordinate~n"),
master(T).

subordinate(Number, Node) ->
spawn(Node, ?MODULE, sp, [Number]).

wait() ->
receive
die -> void
end.

for(N, N, F) -> [F()];
for(I, N, F) -> [F()| for(I+1, N, F)].

I wrote this code myself. Please review this code. I will be happy to issue a push request

@Stratus3D
Copy link
Owner

Sorry it's taken me so long to respond. I'm in the process of updating everything for Chapter 13. I'm working on adding more detailed comments to all the exercises. Last night I pushed the solution for exercise 13.4. Hoping to push the solution for 13.5 sometime this week.

@7stud
Copy link

7stud commented May 10, 2017

In all your README.md files you need to leave a space after the ### marks for them to create headings:

###MyHeading

v.

### MyHeading

This is how it's rendered:

###MyHeading

v.

MyHeading

@Stratus3D
Copy link
Owner

@7stud thanks. I've fixed the formatting of all the README files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants