libev: notify only one process when multiple processes are listening socket
trafdev
trafdev at mail.ru
Tue Jul 16 20:35:33 CEST 2013
I don't want to introduce threads or IPC mechanisms.
Currently I have a solution where N similar processes are launched from
command line,
listening on N different ports and there is a balancer which listens on
one port and forwards requests
to one of N ports in round-robin fashion.
This works and scales very well without unnecessary threads and IPC.
I want to implement same using only one main executable, I believe it's
possible (one of possibilities is:
int wrk = thread::hardware_concurrency();
while (--wrk) {
pid_t pid = fork();
if (pid == 0) {
ev::default_loop().post_fork();
ev::default_loop().run();
return true;
}
}
ev::default_loop().run();
return true;
It works but makes a little overhead on connections acceptance.
On Tue Jul 16 10:17:02 2013, Marc Lehmann wrote:
> On Mon, Jul 15, 2013 at 05:18:33PM -0700, trafdev <trafdev at mail.ru> wrote:
>> N-1 of them getting "resource temporaly unavailable (eagain) while
>> accepting incoming connection, one wins and handles connection.
>>
>> Is it possible to get notification on the socket descriptor only in
>> one process and not waste resources of others?
>
> Use some kind of exclusion mechanism so only one event loop has a watcher
> active at a time, or use only a single shared event loop (e.g. in a
> leader/follower configuration).
>
> Libev or any lower levels cannot help you in this case, as they don't
> know that your application is going to call accept multiple times in the
> future.
>
More information about the libev
mailing list