Skip to content

Latest commit

 

History

History

pool

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Worker Pool

Reading material

Exercise

For this exercise create a pool of workers to compute a standard {M, F, A} or {F, A}.

You will write a gen_server that controls the pool of workers.
The supervision tree will look like this:

Supervision tree

In poolie_sup and poolie_worker_sup you will define appropriate supervision strategies and child specs.

poolie_server implements the following api:

  • run/3: Takes a module, a function and a list of args and dispatches the computation to an idle worker. If all workers are busy, asks user to try again later. - run/2: Same as run/3, but only takes a function and a list of args.
  • pool_info/0: Displays the number of idle and busy workers in the pool.

Your task is to implement the gen_server callbacks in poolie_server, poolie_worker_sup and poolie_worker to handle the work requests.

Example

1> poolie_server:run(fun(X) -> X + 1 end, [5]).
Request is being processed
ok

Got results for {#Fun<erl_eval.6.128620087>,[5]}
Result: 6

2> poolie_server:run(lists, max, [[1,2,3,4,5]]).
Request is being processed
ok

Got results for {lists,max,[[1,2,3,4,5]]}
Result: 5

Notes

  • Think about what supervisor strategies you should use.
  • Should you use gen_server:call or gen_server:cast to send work to your workers?