-
Improvement
-
Resolution: Done
-
High
-
None
FileChannelJournalSegmentReader is using FileChannel methods in rather sub-optimal ways, such as:
long position = channel.position() + memory.position();
channel.position(position);
memory.clear();
channel.read(memory);
channel.position(position);
memory.flip();
While memory.position() is HeapByteBuffer's local field, not shared with anyone else, channel.position() is kernel-side status tied to the channel and hence shared between all users of that channel.
That is problematic for three reasons:
- each call to get or set the position ends up being a system call
- every call needs to be made with FileChannel.positionLock held
- it might be shared resource, hence we set it explicitly before each read – because it may have been set by a different reader, or the writer
All of this dance is done because we do not take advantage of FileChannel API: it offers a read(ByteBuffer, long) method, where the second argument is the desired start position.
Reorganize the code to use that method and maintain the position in a field (IF we really need that).
This will cut down on system calls, as each read will be a single syscall, remove the locking overhead (except on Windows) and, in future, allow us to share a single FileChannel.
- blocks
-
CONTROLLER-2096 Share a single FileChannel between FileChannelJournalSegmentWriter and its readers
- Resolved
- split from
-
CONTROLLER-2043 Circuit breaker timeout with BGP and tell-based protocol
- Resolved