[erlang-questions] Process overhead
Wed Jun 17 16:26:06 CEST 2009
Agreed. Option 1 is the way to go.
The only other possible solution is to create a pool of processes ahead of time, and have a dispatcher function in a gen_server send requests to those processes (but still one process per session). The only advantage of doing this is it removes the small amount of garbage collection that occurs when a process dies. However, it's a bit of work, and probably not needed unless you think there would be any performance gains (not likely).
From: erlang-questions@REDACTED [mailto:erlang-questions@REDACTED] On Behalf Of Torben Hoffmann
Sent: Wednesday, June 17, 2009 10:11 AM
Subject: Re: [erlang-questions] Process overhead
I have no clue on the specific memory and CPU overhead of each process, but
Erlang was designed to provide very little overhead for processes.
Scenario 1 is what Erlang is designed for and personally I have had no
issues with using that approach in real life.
Scenario 2 is kind of like adding some context switching using ETS and I
cannot see how that can be more efficient than keeping some processes alive
(which will be suspended intelligently by the runtime). The only certain
thing you will get with this would be extra code, i.e., more to maintain and
understand, but if you are paid the lines of code then by all means!
On Wed, Jun 17, 2009 at 2:34 PM, Fredrik Svensson <
> I have a gen_server which handles sessions, and I send messages only
> when the session is active. I am concidering two solutions:
> 1. Starting a gen_fsm for each session, each holding the state of the
> session, and ran as long as the session is active.
> 2. Starting gen_fsm:s only to wait for message replys, then terminate
> and save the session-id in an ets table. Then starting a new gen_fsm
> for each message to handle the responses.
> The first solution starts a process for each session, and the second
> only starts a process when a sessions is being used and then save the
> session-id between messages.
> How much is the memory and cpu overhead of each process, do I win
> anything by doing the second solution?
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
More information about the erlang-questions