these are my first steps in Erlang so sorry for this newbie question 🙂 I’m spawning a new Erlang process for every Redis request which is not what I want to (“Too many processes” at 32k Erlang processes) but how to throttle the amount of the processes to e.g. max. 16?
-module(queue_manager).
-export([add_ids/0, add_id/2]).
add_ids() ->
{ok, Client} = eredis:start_link(),
do_spawn(Client, lists:seq(1,100000)).
do_spawn(Client, [H|T]) ->
Pid = spawn(?MODULE, add_id, [Client, H]),
do_spawn(Client, T);
do_spawn(_, []) -> none.
add_id(C, Id) ->
{ok, _} = eredis:q(C, ["SADD", "todo_queue", Id]).
Try using the Erlang
pg2module. It allows you to easliy create process groups and provides an API to get the ‘closest’ (or a random) PID in the group.Here is an example of a process group for the
eredisclient:Here is an example of the above module in action: