AIO and some advice needed.

Alan Bateman Alan.Bateman at Sun.COM
Wed Nov 26 09:16:29 PST 2008


Avinash Lakshman wrote:
> Hi All
>
> I have been evaluating AIO and along the way I learnt that it goes a 
> long to help out the NCQ features that are available in today's SATA 
> drives
The main thing is to have drivers that support it. I don't know what 
operating systems you use but Solaris 10 and Linux have come with AHCI 
drivers for some time. I think you need may special drivers for older 
versions of Windows.

>
>
> (1) Submit the read/write request and then wait on the returned future 
> pointer - which looks like a synchronous read/write to me. It appears 
> one cannot take advantage of NCQ over here.
You could initiate several I/O requests and then iterate over the 
Futures to wait on all the results. The only complication is that you 
would need to deal with short reads (meaning the read completed with 
less bytes that you expected).

> (2) Submit the read/write request and then handle the result in the 
> completion handler as opposed to blocking on a future pointer. This 
> really takes advantage of the NCQ features since the thread is not 
> blocked and more requests can be submitted to take advantage of the 
> NCQ features.
>
> If I were to use the latter how would one handle reads like the ones 
> that occur in our application:
>
> (1) seek(position);
> (2) readUTF() - read a key value.
> (3) readInt() - size of the data associated with the data.
> (4) .....
>
> We need to perform little reads before we know what the result is. 
This may not be a good candidate. Is this a sequential file or do you 
know the file position of data you will need in the future? (in order 
words, does the file position for a read depend on the previous read?)

> So far we were doing buffered reads and then working with the data in 
> to memory. To convert this into true AIO w/o blocking the application 
> thread, would involve some convuluted programming. Is this the norm? 
> Is my understanding correct as far as the programming paradigm is 
> concerned? Are there any samples anyone could share with me that helps 
> me understand this better?
>
Yes, this is the programming model. You either wait for the I/O to 
complete or else you are notified via a completion handler. The sample 
directory doesn't have examples using AsynchronousFileChannel yet (if 
anyone would like to contribute same that would be great).

-Alan.

PS: Did you track down that RandomAccessFile#close problem that you 
think might be a regression in the nio2 builds?



More information about the nio-discuss mailing list