0

There are many parallel requests coming to one erlang OTP (gen_server) process. One process is not sufficient to handle this. I can have fix number pool of same processes to handle this using Poolboy or worker_pool.

But I dont want to have fix set of process pool. I want to create dynamically Process to handle that activity and get killed once it done its work.

So I will be having N numbers of active process for N parallel request. and than it get killed once that process complete the processing.

How I can achieve this?

ManasP
  • 31
  • 6

1 Answers1

2

Use Erlang supervisor module and use transient in its flags.
When your event comes, start new child for doing that and when event done, exit process with reason 'normal'.

Supervisor behavior info: Design - API

Pouriya
  • 1,626
  • 11
  • 19
  • I need more detail like we will have one supervisor and one worker process than how it will have many process running same time? – ManasP Jul 07 '17 at 07:57
  • http://codefather.org/posts/Using_Erlang_process_Load-Balancer_(example).html is this helpful? – Pouriya Jul 07 '17 at 12:49
  • Sorry replying late. I didnt get time to implement your suggestion. Yes it really very helpful. I have used your code and modify it bit as per my need. I have made separate supervisor process who do the call worker_pool:start_link() to start this worker_pool. I am not creating "permanent" child but I am creating "transient" child. also I have to pass few parameters to my Fun() how i can do it? – ManasP Jul 12 '17 at 12:08
  • if you want to supervise your processes and your processes have many different behaviors (crashing with some readable reasons except normal) or they should being restarted after some timeouts, use director as supervisor, https://github.com/pouriya-jahanbakhsh/director – Pouriya Jul 12 '17 at 18:56
  • I think your first suggestion is good enough to solve my problem except two points. 1. I need to pass the parameters to my "fun". how I can do that? 2. I want my worker process to get terminate automatically once its work done i.e. "fun" is executed. I want to add worker process and calling the "fuc" same time and kill it when done. – ManasP Jul 13 '17 at 06:49