This is an automated email from the ASF dual-hosted git repository.

jinrongtong pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/rocketmq.git


The following commit(s) were added to refs/heads/develop by this push:
     new 6d247cb  [ISSUE 3585] [Part J] Use MappedByteBuffer instead of 
FileChannel to write consume queue and slave commitlog. (#3657)
6d247cb is described below

commit 6d247cb3c6bbe77166ad2fb3b7f9a953b57940f9
Author: huangli <[email protected]>
AuthorDate: Mon Dec 27 20:02:57 2021 +0800

    [ISSUE 3585] [Part J] Use MappedByteBuffer instead of FileChannel to write 
consume queue and slave commitlog. (#3657)
    
    This commit improve reput performance and speed up consume qps greatly. In 
our test, produce about 200,000 tps.
    72 queue consume qps: from about 70,000 to 200,000
    600 queue consume qps: from about 70,000 to 110,000
---
 store/src/main/java/org/apache/rocketmq/store/MappedFile.java | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/store/src/main/java/org/apache/rocketmq/store/MappedFile.java 
b/store/src/main/java/org/apache/rocketmq/store/MappedFile.java
index 297271d..774896b 100644
--- a/store/src/main/java/org/apache/rocketmq/store/MappedFile.java
+++ b/store/src/main/java/org/apache/rocketmq/store/MappedFile.java
@@ -236,8 +236,9 @@ public class MappedFile extends ReferenceResource {
 
         if ((currentPos + data.length) <= this.fileSize) {
             try {
-                this.fileChannel.position(currentPos);
-                this.fileChannel.write(ByteBuffer.wrap(data));
+                ByteBuffer buf = this.mappedByteBuffer.slice();
+                buf.position(currentPos);
+                buf.put(data);
             } catch (Throwable e) {
                 log.error("Error occurred when append message to mappedFile.", 
e);
             }
@@ -259,8 +260,9 @@ public class MappedFile extends ReferenceResource {
 
         if ((currentPos + length) <= this.fileSize) {
             try {
-                this.fileChannel.position(currentPos);
-                this.fileChannel.write(ByteBuffer.wrap(data, offset, length));
+                ByteBuffer buf = this.mappedByteBuffer.slice();
+                buf.position(currentPos);
+                buf.put(data, offset, length);
             } catch (Throwable e) {
                 log.error("Error occurred when append message to mappedFile.", 
e);
             }

Reply via email to