dev@grizzly.java.net

Re: Using read(ByteBuffer[] dsts)/write(ByteBuffer[] srcs) of DatagramChannel/SocketChannel

From: Jeanfrancois Arcand <Jeanfrancois.Arcand_at_Sun.COM>
Date: Mon, 10 Mar 2008 21:08:40 -0400

Hi Yuriy,

Yuriy Cherniavsky wrote:
> Hi Grizzly community.
>
>
>
> I look at many different NIO frameworks and chose Grizzly as a favor.

Great! Thanks!


>
>
>
> During analyzing of most famous NIO frameworks I notice that it does not
> provide the possibility to use read(ByteBuffer[]
> dsts)/write(ByteBuffer[] srcs) or read(ByteBuffer[] dsts, int offset,
> int length)/write(ByteBuffer[] srcs, int offset, int length) methods of
> java.nio.channels.DatagramChannel or java.nio.channels.SocketChannel
> classes.
>

With Grizzly, you can extend the com.sun.grizzly.filter.ReadFilter and do a:

socketChannel.read(bb[]);

For the output, scatter write are known to gives extremely bad
performance as under the hood, the jdk creates a large bb on every
operations. Still, you can do scatter write with grizzly:

com.sun.grizzly.util.OutputWriter.write(bb[]....);

at least this is what we have measured in GlassFish, Sailfin and JXTA.


>
>
> I look deeper in source code of sun jdk1.6 (JNI part) and saw that this
> methods implements by OS function (recvmsg/sendmsg on Linux/Solaris and
> WSARecv/WSASend on Windows). So it will improve the performance in such
> task as mine – some type of proxy.

We can certainly add a new ProtocolFilter that does that inside the
Grizzly Framework...would you be able to help us testing it? Can you
file an RFE here so we can track progress:

https://grizzly.dev.java.net/issues/


>
> Target: process UDP package with some my protocol headers + raw data,
> and if I can use read(ByteBuffer[] dsts)/write(ByteBuffer[] srcs)
> methods, I will pass arrays of two ByteBuffer for read and write where
> second ByteBuffer (raw data) must not wanted any change and even copy
> (only flip or rewind if needed)!
>
>
>
> What are you think about such functionality? Cat it be added to Grizzly
> framework?

Of course :-)

Thanks

-- jeanfrancois


>
>
>
> Truly yours, Yuriy.
>
>
>
>
>
> __________ Information from ESET Smart Security, version of virus
> signature database 2935 (20080310) __________
>
> The message was checked by ESET Smart Security.
>
> http://www.eset.com