Best practices with reading/writing to a Memory Mapped File

Johannes Lichtenberger lichtenberger.johannes at gmail.com
Sat Jun 27 10:50:46 UTC 2020


Hi,

I've fixed my Memory Mapped file implementation using your Foreign Memory
API.

https://github.com/sirixdb/sirix/tree/master/bundles/sirix-core/src/main/java/org/sirix/io/memorymapped

Running my tests (mostly simple integration tests, which test if the stuff
I'm storing can be retrieved again or the result of queries are what I
expect), I can't see a clear performance difference between the
RandomAccessFile implementation

https://github.com/sirixdb/sirix/tree/master/bundles/sirix-core/src/main/java/org/sirix/io/file

and the new memorymapped implementation.

So far, I have to create a new mapping everytime I'm appending to the
memory mapped segment of the underlying file I guess (otherwise the bounds
checks will obviously fail):

https://github.com/sirixdb/sirix/blob/627fa5a57a302b04d7165aad75a780d74e14c2e9/bundles/sirix-core/src/main/java/org/sirix/io/memorymapped/MemoryMappedFileWriter.java#L141

I'm only ever appending data when writing or reading randomly based on
offsets.

I haven't done any microbenchmarks as of now and did not check bigger files
ranging from 1Gb to much more nor did I use a profiler to check what's
going on. However, maybe creating the mapping often times is costly and
maybe you can simply spot a performance issue. Or it's IntelliJ and my
rather small flles for testing as of now.

Will next check if importing a 3,8 Gb JSON file is faster or iterating
through the whole imported file with around 400_000_000 nodes :-)

If anyone wants to check it it's simply changing

private static final StorageType STORAGE = StorageType.FILE;

to

private static final StorageType STORAGE = StorageType.MEMORY_MAPPED;

in the class: org.sirix.access.ResourceConfiguration

Thanks for all the suggestions and hints so far
Johannes


More information about the panama-dev mailing list