[erlang-questions] Erlang processes and state management design
Wed Oct 24 12:00:31 CEST 2007
So, I am gradually understanding the design philosophy of an Erlang
On the one hand, functionnal programming is about having no state.
However, in the situation of a Web application, you obviously need to
keep some state otherwise you are back to PhP style (in the sense you
are recalculating everything at each request).
I went back to Joe's book and read again the chapter on processes.
And, as someone suggested earlier, I realized the state of an Erlang
program can actually be kept in a process. So when designing an
application, you indeed model the processes, then the state of the
processes, then the messages.
So for example, if I create a process for each user who logs in to a
program. Upon creation of the process I could fetch all the features
and worklists the user has, then keep them in his process until he
logs out (or after a given long timeout).
I can do that for every task which needs to keep a state between
Therefore, I have a question: where is it usuall or reasonnable to
keep the state of a process?
1) in the parameters of the function we spawn
2) in the process dictionnary
3) in an ETS structure
4) in a in-memory mnesia structure
I suppose it really depends on the amount of data and how it will be
modified (and if we want to keep persistent some session data after
the process is killed).
Tell me if I am wrong, but the first two solutions will put data on
the process stack and will be destroyed when the process is killed.
The two other solutions will have to be cleaned out when the process
Are there some guidelines?
For a user process, I might have 30 or 40 features in a list, some
values about his account, etc...
For a process managing (for example) browsing patients in a list, I
will have the list of patients with the visits for the currently
selected patient, etc...
Thanks for any hints!
4 ch. de la Tour de Champel
Tel: 022 347 77 37
Fax: 022 347 77 38
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions