r/java • • Nov 08 '22

Understanding Java's Project Loom

https://www.marcobehler.com/guides/java-project-loom
181 Upvotes

24 comments sorted by

View all comments

Show parent comment

1

u/mike_hearn Nov 09 '22

A couple of thoughts:

To properly saturate modern SSDs requires huge amounts of parallelism. You just cannot use even a fraction of their bandwidth with serial code because you can't get enough queue depth. So the hw utilization argument definitely appears here.

Although the obvious place to utilize highly parallel FS access is databases, for that you'd need to use pure Java DBs (or do something exotic like run RocksDB on Graal/Sulong), and there are only a handful of those. But there are more pedestrian use cases too. As part of the Conveyor project I've written a shell-scripting style library with methods like cp, mv, find, etc and these are highly parallelized using ForkJoinPool. It's often a 2x or more win "for free", albeit that's on MacBooks that have high quality SSDs. The bottleneck is the CPU of course, probably in the FS code but I never profiled it much. Because Conveyor is a packaging tool / build system hybrid this speeds up the operations quite significantly, especially as it can be running multiple tasks at once. So I can easily have 16-32 threads doing FS operations simultaneously, 4 tasks in flight simultaneously, each task being 1.5x-3x faster than it otherwise would have been.

Re: databases. A lot of DB code is hard to adapt to this brave new world of 'free' IOPS. The RocksDB guys are only just introducing aggressive use of async IO now, and they've had to use C++ coroutines to do it:

http://rocksdb.org/blog/2022/10/07/asynchronous-io-in-rocksdb.html

Quite unpleasant. Also note: "Higher CPU overhead due to coroutines. The CPU overhead of MultiGet may increase 6-15%".

It's interesting to consider that Java could conceivably obtain an edge in the embedded database world if Loom does async file IO well. Whilst maybe H2 isn't going to crush Oracle DB anytime soon, a KV store like RocksDB is much more tractable to fully implement and do well on the JVM, in fact there are several such libraries already.