You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ratis.apache.org by "Tsz-wo Sze (Jira)" <ji...@apache.org> on 2022/10/13 10:28:00 UTC

[jira] [Resolved] (RATIS-1717) Perf: Use global serialize buf to avoid temp buf

     [ https://issues.apache.org/jira/browse/RATIS-1717?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Tsz-wo Sze resolved RATIS-1717.
-------------------------------
    Fix Version/s: 3.0.0
       Resolution: Fixed

The pull request is now merged. Thanks [~William Song]!

> Perf: Use global serialize buf to avoid temp buf
> ------------------------------------------------
>
>                 Key: RATIS-1717
>                 URL: https://issues.apache.org/jira/browse/RATIS-1717
>             Project: Ratis
>          Issue Type: Improvement
>          Components: performance, server
>            Reporter: Song Ziyang
>            Assignee: Song Ziyang
>            Priority: Major
>             Fix For: 3.0.0
>
>         Attachments: 762_review.patch
>
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> In current implementation, before a log entry is serialized to RaftLog, it first needs to be serialized to a byte array[1], and then be written to FileChannel using directByteBuffer[2]. It requires two data copies, one from LogEntryProto to byte array, one from byte array to direct ByteBuffer.
> We can reduce the data copy by *serializing LogEntry to directByteBuffer, removing the byte array:*
>  # We need a directByteBuffer large enough to hold a single log (maxBufferSize).
>  # When we need to serialize a log entry to RaftLog, first we check whether there's enough space remained in directByteBuffer. If not, we flush the directByteBuffer to FileChannel. Otherwise we serialize the data directly into directByteBuffer.
>  # When data buffered in directByteBuffer reaches the threshold (say 64KB), we flush the directByteBuffer, the same as current implementation.
> [1] [https://github.com/apache/ratis/blob/289db3ae64e8cf620eba882468dda661af0439bc/ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/SegmentedRaftLogOutputStream.java#L96]
> [2] [https://github.com/apache/ratis/blob/289db3ae64e8cf620eba882468dda661af0439bc/ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/BufferedWriteChannel.java#L65]
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)