[
https://issues.jboss.org/browse/JGRP-815?page=com.atlassian.jira.plugin.s...
]
Bela Ban commented on JGRP-815:
-------------------------------
Correction: we can connect a *sender's* multicast socket to the mcast_addr, e.g.
{code:java}
DatagramChannel ch=DatagramChannel.open(StandardProtocolFamily.INET)
.setOption(StandardSocketOptions.SO_REUSEADDR, true)
.bind(new InetSocketAddress(7500))
.setOption(StandardSocketOptions.IP_MULTICAST_IF, ni);
SocketAddress mcast_addr=new InetSocketAddress(addr, 7500);
ch.connect(mcast_addr);
{code}
This allows us to use _gathering writes_ to send multiple buffers in one go. On the
receiver side, we cannot connect the sockets, as we don't know the IP addresses of the
senders and we'll have multiple senders sending data, so scattering reads cannot be
used there.
This shouldn't be an issue though, as we may not need scattering reads on the receiver
side.
See attached programs for an example: bla10 is the receiver and bla9 the sender.
Scatter/Gather to avoid copying
-------------------------------
Key: JGRP-815
URL:
https://issues.jboss.org/browse/JGRP-815
Project: JGroups
Issue Type: Sub-task
Reporter: Bela Ban
Assignee: Bela Ban
Fix For: 4.0
When we invoke Channel.send(), we pass a bufffer to JGroups. At the transport level,
JGroups marshals the sender and destination address, plus all headers and the buffer into
a new byte[] buffer, which is then passed to the socket (DatagramSocket, MulticastSocket,
Socket).
We cannot do gathering writes on a DatagramSocket because DatagramSocket doesn't
expose this functionality, contrary to a DatagramChannel.
We could avoid having to copy the user's buffer by using gathering writes:
effectively passing to the socket NIO ByteBuffers containing:
1: Src and dest address plus flags, plus possibly size
2: The marshalled headers
3: The buffer passed to JGroups by the user
We can obtain a gathering-write channel as follows:
ByteBuffer[] buffers; // contains the 3 byte buffers above
DatagramSocket sock;
DatagramChannel ch=sock.getChannel();
ch.write(buffers, 0, length); // length is the number of bytes of the total marshalled
message
This is supported by a GatheringByteChannel.
I don't think there's currently a need to do scattered reads, but this needs to
get investigated more. Also investigate whether MulticastSockets support gathering writes
(whether they expose the correct DatagramChannel).
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)