> I'm curious what you're trying to achieve at a high level though, maybe there 
> is another way that doesn't require FDs being sent across processes?

@AMIGrAve already answered, but I'd like to add: This is the most efficient way 
to do hand-off between processes if you can do, whether it is a listening 
socket or a connected one.

If all is symmetric, (e.g. multiprocess nginx), then you can have multiple 
processes listening on the same port; Another common way to deal with this is 
the old "accept-and-fork", which works very well for long lived connections 
where overall processing dominates the forking time -- but not with e.g. 
preforking or long-lived backends.

Unfortunately, the most common way to deal with it -- especially if the backend 
is itself a long-lived process -- is for the original accepting process to 
proxy to the actual backend. This is wasteful in cpu , memory, kernel 
resources, and also requires the proxying process to remain up and responsive 
(adding latency and reducing reliability). While this is a necessary evil if 
backends are on a different machine, it is a complete waste if all is running 
on the same machine - and with 32-64 core servers relatively common these days 
(especially with containers), it is often the case that you can use the more 
effiicient route.

The other way to avoid sending FDs is shared memory - which is just a bit less 
efficient than transferring the FD (basically, just another memory copy and 
almost uncontended synchronization), but still has the latency/reliability 
drawback, and is significantly more complicated to get right.

It's available on Linux and most Unix variants, but not on Windows AFAIK.

Reply via email to