4 ms·
you can memory-map files in chunks and keep references to the mapped buffers or evict them once a certain limit is reached. note that mapped buffers are not ne
by the8472 9y ago
you can memory-map files in chunks and keep references to the mapped buffers or evict them once a certain limit is reached.
note that mapped buffers are not necessarily backed by RAM, they act more like swap space, except it goes straight to the original file instead of a swap partition. the downside is that anything reading from the buffer can unpredictably incur IO overhead if there's memory pressure and the OS decides to not back them with memory. java doesn't have an api to check residency of buffers. a possible workaround is to first queue them up on a separate thread and forcing them in before using. if they're already there it should have low latency. if they aren't then only the victim thread eats the IO penalty.
- atomashpolskiy 9y agoSo, something like LRU cache of MappedByteBuffers, one buffer per chunk (i.e. "piece")? I wonder what queueing strategy would look like, just enqueue a couple of subsequent pieces when one is requested and loaded?
- the8472 9y agoStart simple, then heap on optimizations if there are latency or throughput issues.
- the8472 9y ago> java doesn't have an api to check residency of buffers. Too late to edit now, but I misremembered that part. I think the issue was that isLoaded was not entirely reliable.