Background:
I have a Java application which does intensive IO on quite large memory mapped files (> 500 MB). The program reads data, writes data, and sometimes does both.
All read/write functions have similar computation complexity.
I benchmarked the IO layer of the program and noticed strange performance characteristics of memory mapped files:
- It performs 90k reads per second (read 1KB every iteration at random position)
- It performs 38k writes per second (write 1KB every iteration sequentially)
- It performs 43k writes per second (write 4 bytes every iteration at random position)
- It performs only 9k read/write combined operation per second (read 12 bytes then write 1KB every iteration, at random position)
The programs on 64-bit JDK 1.7, Linux 3.4.
The machine is an ordinary Intel PC with 8 threads CPU and 4GB physical memory. Only 1 GB was assigned to JVM heap when conducting the benchmark.
If more details are needed, here is the benchmark code: https://github.com/HouzuoGuo/Aurinko2/blob/master/src/test/scala/storage/Benchmark.scala
And here is the implementation of the above read, write, read/write functions: https://github.com/HouzuoGuo/Aurinko2/blob/master/src/main/scala/aurinko2/storage/Collection.scala
So my questions are:
- Given fixed file size and memory size, what factors affect memory mapped file random read performance?
- Given fixed file size and memory size, what factors affect memory mapped file random write performance?
- How do I explain the benchmark result of read/write combined operation? (I was expecting it to perform over 20K iterations per second).
Thank you.