Multiple instances of a gen_server

I have a gen_server module, it does some periodic work: reads from the db, writes to another and sleeps. I want to scale it, and start multiple instances of the server. I do it in the following way:

def children_spec do
    0..@workers_number - 1
    |> Enum.map(
         fn (i) ->
           process_name = String.to_atom("#{__MODULE__}.#{i}")
           Supervisor.child_spec({__MODULE__, name: process_name}, id: {__MODULE__, i})
         end
       )
  end

The module has that children_spec function, which returns list of the child specifications that will be added to the list of the top level application supervisor:

children = children ++ MyWorkerModule.children_spec()
Supervisor.init(children, strategy: :one_for_one)

Is there another way to do that? Also i thought about additional supervisor for the module with the :simple_one_for_one strategy

I think an extra simple one for one supervisor is the one you want in this case.

When you say “sleeps” how do you mean? You have to be careful and preferably not suspend the process for example by doing :timer.sleep(msecs) as a behaviour should always be available to handle requests. A better way is to use :erlang.send_after/3 which sends you a message after a certain time (or at a certain time).

Just wondering.