Imagine the following scenario:
- Parent process opens listening socket, but will never accept() on it. Opening in parent so future forked child processes will inherit the fd, and because it's a low port (perhaps) and we want to open it before we drop root.
- Child processes (one per CPU) inherit listening fd, but they're event-based, handling many
( Read more... )
Comments 31
Reply
Reply
Reply
Reply
Reply
Reply
Reply
Something like http://search.cpan.org/~addi/File-FDpasser-0.09/ does it.
Reply
Either way I have to:
1) wait for readability
2) notify child
3) accept
It might even be better to have the child accept, as that's
spread out between multiple CPUs.
With fd passing, I'm just introducing portability and dependency problems.
Reply
(The comment has been removed)
Reply
Instead have a token (or a few of them) that get passed among the child processes; if a child has the token then they put the fd in their select/epoll/etc., otherwise they don't. Once they accept a new connect they pass the token to the "next" child process. That at least lets you control the size of the herd, which will be equal to the number of tokens in circulation.
Reply
How many children are you talking about here? In Qpsmtpd I basically launch one per CPU, and while yes, 4 processes get notified about readability, it's really not a big deal.
I did try the send_fd/read_fd method, and the pipe to children method, but neither really helped any as far as I could see.
Perhaps it's time to do some real world testing to see if it's really an issue for your app.
Reply
Leave a comment