I need to send/fan-out the same message to a list of hosts through tcpip sockets efficiently. The logic would require looping through each socket to write the message out. If this logic runs in the linux user mode, the underlying OS will call the system call as many times as the number of hosts. This is expensive since each system call requires user-mode to kernel-mode context switch.
It would be more efficient if the loop can be moved in a system call that takes a list of hosts (file descriptors). Does such system call exist in linux?
If such system call exists, do we have an equivalent API in Java (similar to transferTo() in Java corresponds to sendfile() in linux)?