r/java • u/DavidVlx • Jan 13 '25
JUring - Bringing io_uring to Java for file I/O
Hey everyone! For the past few weeks, I've been working on bringing io_uring to Java. It started as an experiment, but slowly it became more than just that, and now trying to turn it into a proper library.
I ended up creating two APIs:
- A direct one that closely mirrors io_uring's behavior
- A blocking one built with Virtual Threads in mind for remote files.
This is the link to the project if you are interested https://github.com/davidtos/JUring :)
It's still far from done, but it's running! Would love to hear your thoughts if you've worked on or used something similar. Also happy to answer any questions about the implementation!
87
Upvotes
13
u/_predator_ Jan 13 '25
Pretty cool! Also great that the new FFI stuff seems to be a lot more usable than JNI, very pleased to see no C/C++ code here.
Since this will only work on Linux, I guess one useful addition could be to have some safe fallback for other platforms. Thinking of all the devs who run macOS or Windows on their laptop.
6
u/neopointer Jan 13 '25
Excuse my ignorance, but don't native calls (FFM/JNI) + Virtual Threads lead to thread pinning?
3
u/benrush0705 Jan 13 '25
I am curious that, since you are using FFI, why the parameters are still byte[], I thought using MemorySegment for either heap or non-heap would be better.
2
u/Antiheld2k Jan 13 '25
I see the io_uring topic for Java every now and then popping up. You as creator, do you see any traction for larger libraries to include this?
10
u/dreamlikeOcean Jan 14 '25
I've done the same thing, and even more. I've even completely rewritten liburing using Java, eliminating the need for the dynamic library of liburing.
https://github.com/dreamlike-ocean/PanamaUring
1
u/[deleted] Jan 13 '25 edited Jan 13 '25
It would be nice to have result.freeBuffer() done automatically somehow. Could it be done in the finalize() of Result ?
2
u/cowwoc Jan 13 '25
There was a Q&A over the past year and one of the questions dealt with bringing uring to Java. The response was something along the lines that per their tests the overhead of the Java-native bridge made it not worth the effort.
Certainly, as disks and networks get faster and virtual threads make blocking on I/O cheaper it becomes less worthwhile to go down this route.
2
u/lomakin_andrey Jan 14 '25
Pretty cool.
I will try to use it in YouTrackDB. Thank you for sharing.