Alpha Sierra
Alpha Sierra

Reputation: 133

Elixir OTP design - how many process

I am working on Elixir OTP application design. I have following choices to make in terms of application design.

The following are two design.

|---supervisor
|   |---handler for work #1 (GenServer)
|       |--handler task  (Task)
|   |---handler for work #2  (GenServer)
|       |--handler task (Task)
|   |----handler for work #3 (GenServer)
|       |--handler task (Task)

Each handler executes different kind of work (like fetch twitter, fetch news etc).

The supervisor dynamically runs one or more handler. The handlers are executed every few seconds to fetch different kind of work.

The tasks types are limited (like log data or post data) each handler will fetch and either log the data or post the data. The handler for work fetches data and generate a task to process and post the data.

In above design the life cycle of task will be till logging or posting the data and life cycle of work handler will be till fetching the single or multiple record. The supervisor will again dynamically run the handler after few seconds.

The same can be designed in following way as well.

|---supervisor (handler)
|   |---handler for work #1 (GenServer)
|   |---handler for work #2 (GenServer)
|   |---handler for work #3 (GenServer)
|---supervisor (task)
|   |---handler for task #1 (GenServer)
|   |---handler for task #2 (GenServer)

In above design two supervisor would handle work and task respectively.

The handler for task will be registered under local aliases. The handler for work will send message to respective task for further processing.

Is there any limitations with these approach and which one is suggested for concurrent design as per OTP.

Upvotes: 1

Views: 196

Answers (1)

Alpha Sierra
Alpha Sierra

Reputation: 133

This is how I have planned to implement. With a minor change.

|---supervisor (handler)
|   |---handler for work #1 (GenServer)
|       |--handler task  (Task)
|   |---handler for work #2 (GenServer)
|       |--handler task  (Task)
|   |---handler for work #3 (GenServer)
|       |--handler task  (Task)

Instead of supervisor dynamically running handler every few second. Each handler will be run and supervised. The handler will in turn create a Task every few seconds.

Upvotes: 0

Related Questions