Uploaded image for project: 'Apache RocketMQ'
  1. Apache RocketMQ
  2. ROCKETMQ-274

Some code may be can improvement

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Not A Problem
    • 4.2.0
    • 4.2.0
    • rocketmq-store
    • None

    Description

      in class [CommitLog]
      I see many put Int or Long operation like this in function doAppend(...), We will result a better performance if we use DirectByteBuffer instead of HeapByteBuffer and use unsafe to operate the buffer.

      // Initialization of storage space
                  this.resetByteBuffer(msgStoreItemMemory, msgLen);
                  // 1 TOTALSIZE
                  this.msgStoreItemMemory.putInt(msgLen);
                  // 2 MAGICCODE
                  this.msgStoreItemMemory.putInt(CommitLog.MESSAGE_MAGIC_CODE);
                  // 3 BODYCRC
                  this.msgStoreItemMemory.putInt(msgInner.getBodyCRC());
                  // 4 QUEUEID
                  this.msgStoreItemMemory.putInt(msgInner.getQueueId());
                  // 5 FLAG
                  this.msgStoreItemMemory.putInt(msgInner.getFlag());
                  // 6 QUEUEOFFSET
                  this.msgStoreItemMemory.putLong(queueOffset);
                  // 7 PHYSICALOFFSET
                  this.msgStoreItemMemory.putLong(fileFromOffset + byteBuffer.position());
                  // 8 SYSFLAG
                  this.msgStoreItemMemory.putInt(msgInner.getSysFlag());
                  // 9 BORNTIMESTAMP
                  this.msgStoreItemMemory.putLong(msgInner.getBornTimestamp());
                  // 10 BORNHOST
                  this.resetByteBuffer(hostHolder, 8);
                  this.msgStoreItemMemory.put(msgInner.getBornHostBytes(hostHolder));
                  // 11 STORETIMESTAMP
                  this.msgStoreItemMemory.putLong(msgInner.getStoreTimestamp());
                  // 12 STOREHOSTADDRESS
                  this.resetByteBuffer(hostHolder, 8);
                  this.msgStoreItemMemory.put(msgInner.getStoreHostBytes(hostHolder));
                  //this.msgBatchMemory.put(msgInner.getStoreHostBytes());
                  // 13 RECONSUMETIMES
                  this.msgStoreItemMemory.putInt(msgInner.getReconsumeTimes());
                  // 14 Prepared Transaction Offset
                  this.msgStoreItemMemory.putLong(msgInner.getPreparedTransactionOffset());
                  // 15 BODY
                  this.msgStoreItemMemory.putInt(bodyLength);
                  if (bodyLength > 0)
                      this.msgStoreItemMemory.put(msgInner.getBody());
                  // 16 TOPIC
                  this.msgStoreItemMemory.put((byte) topicLength);
                  this.msgStoreItemMemory.put(topicData);
                  // 17 PROPERTIES
                  this.msgStoreItemMemory.putShort((short) propertiesLength);
                  if (propertiesLength > 0)
                      this.msgStoreItemMemory.put(propertiesData);
      

      after the puts , at the line 1305:

      byteBuffer.put(this.msgStoreItemMemory.array(), 0, msgLen);
      

      it always put from zero of this buffer , but the resetByteBuffer function use flip() to "clean ?" the buffer , what if just do clear() the buffer in the function and limit it outside when need.

      Attachments

        Activity

          People

            yukon Xinyu Zhou
            wk10000 wangkai
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: