Gen_server and Gen_fsm questions
Joe Armstrong (AL/EAB)
Tue Jan 4 11:16:26 CET 2005
> If I have one/two process for each call, then if I maintain let's say
> 100,000 simultaneous calls, I will have to create 200,000 gen_fsm, ie.
> Is that a Good method?
> Will that create unnecessary system overhead?
It's exactly the right way to think.
You have to get used to thinking in terms of processes - creating processes
is a light-weight operation (this means you can create lot's of them very quickly).
No you might run into memory problems - I don't know what the minimum size of a process is
but let's guess 1KB - so your 200 K process might take 200M of memory and that might
be a problem.
But suppose you were to do it some other way - suppose you "suspend" a process when it's not
doing anything useful - you have to store it's data structures somewhere - you have to
make it go away, store it's data structures, then at a later stage wake it up and
restore it's data structures etc. All of this takes lots of unnecessary code and there's no guarantee that it's quicker.
Even storing the data structures required by suspended processes takes space so doing this might not be a good idea.
The Erlang "way" is to identify all the truly parallel activities in your application and then assign exactly ONE process per activity. (The exactly ONE bit is important) -
this makes the code isomorphic to the problem - and easy to write understand and debug.
So first you do as I have suggested - THEN you measure and possibly optimise.
First make it right - then make it fast.
Happy new Year
More information about the erlang-questions