I made a load test for rocketmq, then I found a lot of long call,the long call cost much more then 100ms.But I read the source code of the long call,the main cost is the writing of bytebuffer. The core code like this:
public AppendMessageResult doAppend(final long fileFromOffset,
final ByteBuffer byteBuffer, final int maxBlank,
final MessageExtBrokerInner msgInner) {//from CommitLog.java
...
final long beginTimeMills = CommitLog.this.defaultMessageStore.now();
byteBuffer.put(this.msgStoreItemMemory.array(), 0, msgLen);
AppendMessageResult result = new AppendMessageResult(AppendMessageStatus.PUT_OK, wroteOffset, msgLen, msgId,
msgInner.getStoreTimestamp(), queueOffset, CommitLog.this.defaultMessageStore.now() - beginTimeMills);
return result;
}
The log show the CommitLog.this.defaultMessageStore.now() - beginTimeMills
(pagecacheRT in the log below) cost more than 100ms.
2018-04-09 00:24:41 WARN SendMessageThread_1 - [NOTIFYME]putMessage in lock cost time(ms)=517 nano time(ms)=516, bodyLength=130 AppendMessageResult=AppendMessageResult{status=PUT_OK, wroteOffset=3113603972920, wroteBytes=128, msgId='0A0C240300002A9F000002D4F1423F38', storeTimestamp=1523204680621, logicsOffset=11016755, pagecacheRT=517, msgNum=1}
The pagecacheRT
is the put operation time cost.Then I saw the byteBuffer initialize code, like this:
public void init() {
for (int i = 0; i < poolSize; i++) {
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(fileSize);
final long address = ((DirectBuffer) byteBuffer).address();
Pointer pointer = new Pointer(address);
LibC.INSTANCE.mlock(pointer, new NativeLong(fileSize));
availableBuffers.offer(byteBuffer);
}
}
The bytebuffer just is a directBuffer. My test environment is a pyhsical machine with 32 processor and 96G memory,And write bytes is 125byte pre write. I saw the monitor during the load test, the CPU and disk is very healthy.I don't think this problem is casued by the implements of rocketmq.Because the main code is very simple,just is the above section code.
But I cannot understand why a writing of memory can cost so much time.Is there any way to understanding these or something?
Thanks in advance!