On 07/22/2014 12:32 AM, Chris Dickinson wrote:
> Hi all,
> 
> I'm currently working on a feature for Node that would allow Node to
> apply backpressure to incoming socket connections -- specifically,
> letting them pool in the kernel if JS is currently busy.
> In the course of implementing this feature, I found that it was
> impossible to keep libuv from accept()'ing the socket from the Node
> side. Specifically, uv__server_io calls accept() before the
> connection_cb() [1]. In order to let the client apply backpressure /
> keep sockets waiting in the kernel queue, it would be necessary to move
> the accept() call & associated logic into uv_accept, 
> so that the connection_cb() can trigger accept() itself. Is this a sane
> course of action? The only caveat I saw was that the emfile trick[2]
> would have to be moved / otherwise accounted for somehow.
> 
> Thanks for your feedback!
> Chris
> 
> [1]: 
> https://github.com/joyent/libuv/blob/06c60e9662fea752d77237857bbf2c9ea5889a00/src/unix/stream.c#L468
> [2]: 
> https://github.com/joyent/libuv/blob/06c60e9662fea752d77237857bbf2c9ea5889a00/src/unix/stream.c#L415
> 

I guess some uv_listen_stop would also work for you, right? The idea
being that you stop listening for new incoming connections for a while
(for example to mitigate EMFILE).

We do have some plans, which we'll put together and share after libuv
0.12 is released, but in a nutshell uv_listen would be going away, along
with the current incarnation of uv_accept.

The new uv_accept will be a request, which completes when a new
connection is accepted, gives you the fd, and you can then create a
handle with it. There are some details to be polished, but that's the idea.

So, havin libuv 0.12 around the corner, and considering we already have
plans to change uv_listen / uv_accept, I'm not sure I'd like to change
the behavior to something else in the meantime.

Cheers,

-- 
Saúl Ibarra Corretgé
bettercallsaghul.com


Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to