bbeaupain / nio_uring

High performance I/O library for Java using io_uring under the hood
MIT License
146 stars 8 forks source link

Implement common interfaces #13

Open mattrpav opened 1 year ago

mattrpav commented 1 year ago

It would be great if there was a IoUringFile class that implemented common interfaces.

This would allow providing io_uring-based file providers for existing platforms.

java.io.DataOutput, java.io.DataInput, java.io.Closeable

bbeaupain commented 1 year ago

This is a great idea that would really enhance the utility of the project.

One thing that may cause confusion though, is that no I/O operations will execute unless execute() is called on the ring, or there is a thread in the background running the loop() method. Wondering what your thoughts are on how to approach this, or is documentation enough?

mattrpav commented 1 year ago

How about something along the lines of a RandomAccessFileFactory?

  1. start() / stop() methods to handle the state of the ring buffers and if a dedicated thread is needed
  2. createRandomAccessFile() method to pass a io_uring enabled-File instance to applications?
bbeaupain commented 1 year ago

Great points, however this does have implications that may require changing the way the nio_uring API is designed. At this time, all I/O operations are called on an IoUring object as opposed to the file or socket object; this reflects the internal native approach, where all operations are indeed executed by the liburing API itself.

This would involve moving the read/write/accept methods into the base IoUringChannel class, and having two overloaded versions for each - one that takes an IoUring as an argument, and one that does not but instead uses a default "internal" ring that runs similar to the ForkJoinPool used for parallel Java streams.

I'll think on this though, and see if I can find a less destructive approach.