Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8741981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:25:02+00:00 2026-06-13T11:25:02+00:00

these are my first steps in Erlang so sorry for this newbie question :)

  • 0

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]).
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:25:03+00:00Added an answer on June 13, 2026 at 11:25 am

    Try using the Erlang pg2 module. 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 eredis client:

    -module(redis_pg).
    
    -export([create/1,
             add_connections/1, 
             connection/0,
             connections/0,
             q/1]).
    
    create(Count) ->
        % create process group using the module name as the reference
        pg2:create(?MODULE),
        add_connections(Count).
    
    % recursive helper for adding +Count+ connections
    add_connections(Count) when Count > 0 ->
        ok = add_connection(),
        add_connections(Count - 1);
    add_connections(_Count) -> 
        ok.
    
    add_connection() ->
        % start redis client connection
        {ok, RedisPid} = eredis:start_link(),
        % join the redis connection PID to the process group
        pg2:join(?MODULE, RedisPid).
    
    connection() ->
        % get a random redis connection PID
        pg2:get_closest_pid(?MODULE).
    
    connections() ->
        % get all redis connection PIDs in the group
        pg2:get_members(?MODULE).
    
    q(Argv) ->
        % execute redis command +Argv+ using random connection
        eredis:q(connection(), Argv).
    

    Here is an example of the above module in action:

    1> redis_pg:create(16).
    ok
    2> redis_pg:connection().
    <0.68.0>
    3> redis_pg:connection().
    <0.69.0>
    4> redis_pg:connections().
    [<0.53.0>,<0.56.0>,<0.57.0>,<0.58.0>,<0.59.0>,<0.60.0>,
     <0.61.0>,<0.62.0>,<0.63.0>,<0.64.0>,<0.65.0>,<0.66.0>,
     <0.67.0>,<0.68.0>,<0.69.0>,<0.70.0>]
    5> redis_pg:q(["PING"]).  
    {ok,<<"PONG">>}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all sorry for my bad english and Im pretty new in these
Alright this is my first day with JQuery so have fun with these functions
Note that these are my first steps in the world of C# so I
I'm learning Haskell, and these are my first steps in trying to understand the
Im moving first steps into JSF framework. I so make these jsp/bean : index.jsp
I have the following which works well: def steps %w[hello billing confirmation] end steps.first
I have the following which works well: def steps %w[hello billing confirmation] end steps.first
I'm new to JavaEE and EJBs. I made my first few steps with it
These are my first steps with RichFaces and Maven. I've stuck on the error
For my first steps into Lift I just started with this tutorial but it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.