Efficiently accepting TCP connections

Sean Hinde sean.hinde@REDACTED
Fri May 13 06:15:47 CEST 2005


Hi,

On 12 May 2005, at 21:20, Corrado Santoro wrote:

> Sean Hinde wrote:
>>  From a quick look at one paper on this subject it appears to be an 
>> attempt to solve the problem where there are more connections than 
>> the language will allow you to have threads.
> On one hand. But on the other hand, the main contribution of the 
> leader-follower is to overcome the overhead introduced by creating 
> threads "on-the-fly" for each incoming connection.

OK, same effect. The point is that managing thread pools is much more 
complicated than just creating a new one every time. You have to track 
which ones are in use, and ensure that there is no leakage under all 
finishing cases.

>
>> Erlang suffers from the opposite effect - it can have many more 
>> threads than the OS will support IO handles !
> OK. So you could create, say 1000 or 10000, sleeping Erlang processes, 
> placing them in a pool, and then pick one process at time for each new 
> connection, passing the connected socket. This avoids latency in 
> connection handling because you don't need to create the process 
> on-the-fly. Then, when processing of the connection is completed, the 
> process can be returned to the pool and made available for a new 
> connection.

You could indeed. And you might gain a small few percent if your aim is 
to make the fastest web server on the planet. The point about Erlang 
though is that process creation is such a lightweight operation that 
efforts to optimise it away are almost always misdirected.

>
>
>> I suggest you scrap such thinking (be it object oriented or "thread 
>> pools") and go with the Erlang way (one process for every concurrent 
>> activity).
> If you have an adequate number of processes in the pool, the behaviour 
> of the overall system is the same as having one process for every 
> concurrent activity. I think.

Yes, but unnecessary and much more complex.

>
> Object orientation is not necessary, it is only a matter of C++/Java 
> implementation of the leader-follower pattern. But its principle holds 
> also in a non OO environment.

Agreed.

Sean




More information about the erlang-questions mailing list