process pools?
Joe Armstrong
joe.armstrong@REDACTED
Tue Oct 9 11:44:40 CEST 2001
Julian Assange wrote:
>Two questions:
>
> 1) ...
>
>
>
> 2) What is the best method to implement worker threads? i.e
> I'd like a pool of processes (one for each outbound
> socket), which listen on the same message queue for
> requests -- the first free process reads gets the
> message.
>
I suspect you don't need to keep a pool of workers - I'd just spawn off
a new process for
each new request (possibly limiting the number of processes that can be
spawned off).
I use tcp_server.erl (appended) for this - this I'm constantly modifying
(one day I'll get it right)
The call tcp_server:start_raw_server(2000, F/1, 25)
starts a listener on port 2000. The fun F/1 is called every time a new
connection is setup on
port 2000. At most 25 parallel sessions are allowed.
Read the comments at the start of the file.
F/1 should go into a receive loop where it can receive gen_tcp messages
This should probably do what you want.
/Joe Armstrong
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: tcp_server.erl
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20011009/824600c5/attachment.ksh>
More information about the erlang-questions
mailing list