C
Chris
What's the best approach for heavily concurrent read access to a file?
I have a file that needs to be read by many threads. The file is much
too big to fit in memory. I'll do some caching, but access is mostly
random so there will be a large number of cache misses.
Unfortunately, RandomAccessFile is single threaded. To read data, you
much call seek() and then read(), and this can only be done one thread
at a time.
I see three possible approaches to the problem:
1. Wrap the calls to seek() and read() in a synchronized method. This
will be slow.
2. Have a pool of RandomAccessFile objects all pointing to the same
file. Have each thread grab and release objects from the pool as needed.
The downside here is that many file handles will be required.
3. Do something fancy with NIO and selectors. I haven't looked into this
deep enough to know if it's an option.
What's the best approach?
I have a file that needs to be read by many threads. The file is much
too big to fit in memory. I'll do some caching, but access is mostly
random so there will be a large number of cache misses.
Unfortunately, RandomAccessFile is single threaded. To read data, you
much call seek() and then read(), and this can only be done one thread
at a time.
I see three possible approaches to the problem:
1. Wrap the calls to seek() and read() in a synchronized method. This
will be slow.
2. Have a pool of RandomAccessFile objects all pointing to the same
file. Have each thread grab and release objects from the pool as needed.
The downside here is that many file handles will be required.
3. Do something fancy with NIO and selectors. I haven't looked into this
deep enough to know if it's an option.
What's the best approach?