dev@grizzly.java.net

Re: [Fwd: NIO is hard for the uninitiated...we need help]

From: charlie hunt <charlie.hunt_at_sun.com>
Date: Mon, 26 Mar 2007 16:10:09 -0500

Charles Oliver Nutter wrote:
> Jeanfrancois Arcand wrote:
>> Hi,
>>
>> if peoples are interested to help or share their experience :-)
>>
>> Thanks!
>
> We're really interested in some help here. You can look at
>
> http://jira.codehaus.org/browse/JRUBY-706
>
> ...for one sample of work being done to speed up RandomAccessFile
> usage. However the socket stuff has nobody working on it directly
> right now, and it appears to be very slow.
>
> - Charlie

You might consider trying a MappedByteBuffer with your FileChannel if
you have the address space to work with and/or tend to be looking at the
same file most of the time along with having evidence you are reading
and writing to that file an awful lot.

I'd also try to avoid HeapByteBuffer which is what's returned by
ByteBuffer.allocate().

If you find you have all of your data in byte[]'s, then you may be
better off using HeapByteBuffer. However, note that every time you send
a HeapByteBuffer to a FileChannel, (or a SocketChannel), and when your
read into a HeapByteBuffer from a FileChannel (or a SocketChannel), you
are copying bytes between a byte[] and native space.

I've never been a big fan of copying data and avoid it whenever
possible. However, if you are manipulating your data in byte[]'s, then
you'll ultimately end up copying the data anyway. In such a case, try
to minimize the number of times you actually invoke the operation to
copy data from a byte[] or HeapByteBuffer.

I'd love to be jump in help. But, I'm about 2x over booked already :-(

charlie ...

-- 
Charlie Hunt
Java Performance Engineer
630.285.7708 x47708 (Internal)
<http://java.sun.com/docs/performance/>