On Wed, May 21, 2008 at 11:10 PM, Pauls, Karl <[EMAIL PROTECTED]> wrote:

> If I understand you correctly, then apart from the kernel-level
> implications of zero-copy reads, such a facility to bring bytes into the JVM
> without a copy has existed in the JNI spec since Java 1.4.
>
> http://java.sun.com/javase/6/docs/technotes/guides/jni/spec/functions.html#nio_support
>
> Note that this is an optional part of the JNI specification. So some
> vendors may not support it.
>
> Isn't this how org.apache.tomcat.jni.Pool is implemented?
>

I'm not familar with tomcat, but if e.g. the APR connector supports this
feature, it is free to inject its own kind of bytebuffers to the JVM for
Mina via JNI as far as I understood. The specific implementation (e.g.
Mina's APR transport) should cope with correctly obtaining direct buffers
from JNI then. Standard Nio SocketChannels do not seem to support a
channel.getBuffer() method or similar instead of channel.read(buffer),
though, so that using heap buffers with standard Nio is still the best
choice.

Injecting some sort of direct buffers to Mina is a part of the
particular JNI transport in the first place and will not result in any code
changes to the framework logic behind the transport as pointed out earlier -
which is especially the proposed queue implementation.

In this case, if the JNI transport can also get back a direct buffer (not
just inject it) it may make sence to allocate direct buffers within mina
that can be dealed with in this way to pass it pack to the transport - but
only in this perticular case of using JNI. For this, there is already a
possibility to achive it afaik: Using a custom IoBufferAllocator. I'm not
sure about the possible performance benefits, though. If there is one, it
may be worth thinking about implementing APR etc. perfectly to achive
zero-copy even on read/write from/to JNI. However, the currently planned
changes are not directly connected to this type of optimization because it's
more about the internal use of bytebuffers inside Mina.

But for the JNI transports it is a very good point!

regards
Daniel

Reply via email to