mirror of https://github.com/apache/activemq.git
https://issues.apache.org/jira/browse/AMQ-5578 - enable org.apache.activemq.kahaDB.files.skipMetadataUpdate for tests to validate. remove some redundant call to limit and add latencey test to validate the need for outof band or pool allocation of journals
This commit is contained in:
parent
3e7847aead
commit
930a74c696
|
@ -62,7 +62,7 @@ public class Journal {
|
|||
|
||||
private static final int MAX_BATCH_SIZE = 32*1024*1024;
|
||||
|
||||
private static final int PREALLOC_CHUNK_SIZE = 1 << 20;
|
||||
private static final int PREALLOC_CHUNK_SIZE = 1024*1024;
|
||||
|
||||
// ITEM_HEAD_SPACE = length + type+ reserved space + SOR
|
||||
public static final int RECORD_HEAD_SPACE = 4 + 1;
|
||||
|
@ -282,7 +282,6 @@ public class Journal {
|
|||
|
||||
private void doPreallocationZeros(RecoverableRandomAccessFile file) {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(maxFileLength);
|
||||
buffer.limit(maxFileLength);
|
||||
|
||||
try {
|
||||
FileChannel channel = file.getChannel();
|
||||
|
@ -326,8 +325,6 @@ public class Journal {
|
|||
private void doPreallocationChunkedZeros(RecoverableRandomAccessFile file) {
|
||||
|
||||
ByteBuffer buffer = ByteBuffer.allocate(PREALLOC_CHUNK_SIZE);
|
||||
buffer.position(0);
|
||||
buffer.limit(PREALLOC_CHUNK_SIZE);
|
||||
|
||||
try {
|
||||
FileChannel channel = file.getChannel();
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.store.kahadb.disk.journal;
|
||||
|
||||
import org.apache.activemq.management.TimeStatisticImpl;
|
||||
import org.apache.activemq.store.kahadb.KahaDBStore;
|
||||
import org.apache.activemq.util.ByteSequence;
|
||||
import org.apache.activemq.util.Wait;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class PreallocationJournalLatencyTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(PreallocationJournalLatencyTest.class);
|
||||
final Random rand = new Random();
|
||||
|
||||
@Test
|
||||
public void preallocationLatency() throws Exception {
|
||||
|
||||
TimeStatisticImpl sparse = executeTest(Journal.PreallocationStrategy.SPARSE_FILE.name());
|
||||
TimeStatisticImpl chunked_zeros = executeTest(Journal.PreallocationStrategy.CHUNKED_ZEROS.name());
|
||||
TimeStatisticImpl zeros = executeTest(Journal.PreallocationStrategy.ZEROS.name());
|
||||
LOG.info(" sparse: " + sparse);
|
||||
LOG.info(" chunked: " + chunked_zeros);
|
||||
LOG.info(" zeros: " + zeros);
|
||||
|
||||
}
|
||||
|
||||
private TimeStatisticImpl executeTest(String preallocationStrategy)throws Exception {
|
||||
int randInt = rand.nextInt(100);
|
||||
File dataDirectory = new File("./target/activemq-data/kahadb" + randInt);
|
||||
|
||||
KahaDBStore store = new KahaDBStore();
|
||||
store.deleteAllMessages();
|
||||
store.setDirectory(dataDirectory);
|
||||
store.setPreallocationStrategy(preallocationStrategy);
|
||||
store.start();
|
||||
|
||||
final File journalLog = new File(dataDirectory, "db-1.log");
|
||||
assertTrue("file exists", Wait.waitFor(new Wait.Condition() {
|
||||
@Override
|
||||
public boolean isSatisified() throws Exception {
|
||||
return journalLog.exists();
|
||||
}
|
||||
}));
|
||||
|
||||
final Journal journal = store.getJournal();
|
||||
ByteSequence byteSequence = new ByteSequence(new byte[8*1024]);
|
||||
|
||||
TimeStatisticImpl timeStatistic = new TimeStatisticImpl("append", "duration");
|
||||
for (int i=0;i<300000; i++) {
|
||||
final long start = System.currentTimeMillis();
|
||||
journal.write(byteSequence, true);
|
||||
timeStatistic.addTime(System.currentTimeMillis() - start);
|
||||
}
|
||||
LOG.info("current journal dataFile id: " + journal.getCurrentDataFileId());
|
||||
store.stop();
|
||||
return timeStatistic;
|
||||
}
|
||||
|
||||
}
|
1
pom.xml
1
pom.xml
|
@ -1204,6 +1204,7 @@
|
|||
<failIfNoTests>false</failIfNoTests>
|
||||
<systemPropertyVariables>
|
||||
<java.awt.headless>true</java.awt.headless>
|
||||
<org.apache.activemq.kahaDB.files.skipMetadataUpdate>true</org.apache.activemq.kahaDB.files.skipMetadataUpdate>
|
||||
</systemPropertyVariables>
|
||||
<argLine>-Xmx512m</argLine>
|
||||
</configuration>
|
||||
|
|
Loading…
Reference in New Issue