[Joafip-svn] SF.net SVN: joafip:[2911] trunk
Brought to you by:
luc_peuvrier
|
From: <luc...@us...> - 2011-10-01 17:08:58
|
Revision: 2911
http://joafip.svn.sourceforge.net/joafip/?rev=2911&view=rev
Author: luc_peuvrier
Date: 2011-10-01 17:08:48 +0000 (Sat, 01 Oct 2011)
Log Message:
-----------
IInstanceFactory field are now transient
Modified Paths:
--------------
trunk/joafip/src/main/java/net/sf/joafip/service/ExclusiveDataAccessSession.java
trunk/joafip/src/main/java/net/sf/joafip/store/service/objectio/manager/AbstractObjectIOManagerIOForObject.java
trunk/joafip-4test/src/main/java/net/sf/joafip/autosave/SpellCheckJoafipDAO.java
trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/AbstractPerfService.java
trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/Exporter.java
trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/Garbage.java
trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/Inserter.java
trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/Searcher.java
trunk/joafip-collection/src/main/java/net/sf/joafip/java/util/AbstractPLinkedTreeSet.java
trunk/joafip-collection/src/main/java/net/sf/joafip/java/util/AbstractPTreeSet.java
trunk/joafip-collection/src/main/java/net/sf/joafip/java/util/MapCollectionValues.java
trunk/joafip-collection/src/main/java/net/sf/joafip/java/util/PHashMap.java
trunk/joafip-collection/src/main/java/net/sf/joafip/java/util/PHashMapKeySet.java
trunk/joafip-collection/src/main/java/net/sf/joafip/java/util/PHashSet.java
trunk/joafip-collection/src/main/java/net/sf/joafip/java/util/PLinkedHashMap.java
trunk/joafip-collection/src/main/java/net/sf/joafip/java/util/PLinkedHashSet.java
trunk/joafip-collection/src/main/java/net/sf/joafip/java/util/PLinkedMapKeySet.java
trunk/joafip-collection/src/main/java/net/sf/joafip/java/util/PLinkedTreeMap.java
trunk/joafip-collection/src/main/java/net/sf/joafip/java/util/PMapKeyNavigableSet.java
trunk/joafip-collection/src/main/java/net/sf/joafip/java/util/PSynchronizedList.java
trunk/joafip-collection/src/main/java/net/sf/joafip/java/util/PTreeMap.java
trunk/joafip-collection/src/main/java/net/sf/joafip/java/util/support/arraylist/ArrayListSupport.java
trunk/joafip-collection/src/main/java/net/sf/joafip/java/util/support/hash/HashSupport.java
trunk/joafip-collection/src/main/java/net/sf/joafip/java/util/support/hash/HashSupportIterator.java
trunk/joafip-collection/src/main/java/net/sf/joafip/java/util/support/hash/HashSupportNodeEntry.java
trunk/joafip-collection/src/main/java/net/sf/joafip/java/util/support/linked/hash/LinkedHashSupport.java
trunk/joafip-collection/src/main/java/net/sf/joafip/java/util/support/linked/tree/LinkedTreeSupport.java
trunk/joafip-collection/src/main/java/net/sf/joafip/java/util/support/linkedlist/LinkedListSupport.java
trunk/joafip-collection/src/main/java/net/sf/joafip/java/util/support/tree/TreeSupport.java
trunk/joafip-rbtree/src/main/java/net/sf/joafip/redblacktree/impl/memory/service/RBTNodeManager.java
trunk/joafip-rbtree/src/main/java/net/sf/joafip/redblacktree/service/RedBlackTree.java
Added Paths:
-----------
trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/AbstractInserter.java
trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/AbstractSearcher.java
trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/ImportSearcher.java
trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/Importer.java
trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/InserterFewInsertAndExport.java
trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/MainExportScanner.java
trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/MainExportTransform.java
trunk/joafip-4test/src/main/resources/extract.xsl
Modified: trunk/joafip/src/main/java/net/sf/joafip/service/ExclusiveDataAccessSession.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/service/ExclusiveDataAccessSession.java 2011-10-01 16:45:37 UTC (rev 2910)
+++ trunk/joafip/src/main/java/net/sf/joafip/service/ExclusiveDataAccessSession.java 2011-10-01 17:08:48 UTC (rev 2911)
@@ -39,7 +39,8 @@
private static final String SAVE_ERROR = "save error";
- private final IInstanceFactory instanceFactory = new InstanceFactory(this);
+ private final transient IInstanceFactory instanceFactory = new InstanceFactory(
+ this);
public ExclusiveDataAccessSession(final FilePersistence filePersistence) {
super(filePersistence);
Modified: trunk/joafip/src/main/java/net/sf/joafip/store/service/objectio/manager/AbstractObjectIOManagerIOForObject.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/store/service/objectio/manager/AbstractObjectIOManagerIOForObject.java 2011-10-01 16:45:37 UTC (rev 2910)
+++ trunk/joafip/src/main/java/net/sf/joafip/store/service/objectio/manager/AbstractObjectIOManagerIOForObject.java 2011-10-01 17:08:48 UTC (rev 2911)
@@ -166,7 +166,7 @@
*/
private int zipCompressionLevel = Deflater.BEST_SPEED;
- private IInstanceFactory instanceFactory;
+ private transient IInstanceFactory instanceFactory;
protected final HelperBinaryConversion helperBinaryConversion;
Modified: trunk/joafip-4test/src/main/java/net/sf/joafip/autosave/SpellCheckJoafipDAO.java
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/autosave/SpellCheckJoafipDAO.java 2011-10-01 16:45:37 UTC (rev 2910)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/autosave/SpellCheckJoafipDAO.java 2011-10-01 17:08:48 UTC (rev 2911)
@@ -40,7 +40,7 @@
private IDataAccessSession session;
- private IInstanceFactory instanceFactory;
+ private transient IInstanceFactory instanceFactory;
private SpellCheckBase spellCheckBase;
Added: trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/AbstractInserter.java
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/AbstractInserter.java (rev 0)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/AbstractInserter.java 2011-10-01 17:08:48 UTC (rev 2911)
@@ -0,0 +1,455 @@
+/*
+ * Copyright 2011 Luc Peuvrier
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (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.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * 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 net.sf.joafip.performance.items.service;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.lang.reflect.Field;
+import java.util.List;
+import java.util.Map;
+
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.StorableAccess;
+import net.sf.joafip.entity.EnumFilePersistenceCloseAction;
+import net.sf.joafip.file.entity.PageNode;
+import net.sf.joafip.file.service.RandomAccessFileReadWriteCache;
+import net.sf.joafip.java.util.PLinkedTreeSet;
+import net.sf.joafip.meminspector.service.MemInspectorException;
+import net.sf.joafip.meminspector.service.inspect.MemInspector;
+import net.sf.joafip.meminspector.service.show.ShowObjectTree;
+import net.sf.joafip.performance.items.entity.Item;
+import net.sf.joafip.performance.items.entity.ItemList;
+import net.sf.joafip.performance.items.entity.ItemTemplate;
+import net.sf.joafip.performance.items.entity.ItemTemplateList;
+import net.sf.joafip.service.FilePersistenceClassNotFoundException;
+import net.sf.joafip.service.FilePersistenceDataCorruptedException;
+import net.sf.joafip.service.FilePersistenceException;
+import net.sf.joafip.service.FilePersistenceInvalidClassException;
+import net.sf.joafip.service.FilePersistenceNotSerializableException;
+import net.sf.joafip.service.FilePersistenceTooBigForSerializationException;
+import net.sf.joafip.service.IDataAccessSession;
+import net.sf.joafip.service.MemInspectorJoafipSetup;
+import net.sf.joafip.store.service.StoreClassNotFoundException;
+import net.sf.joafip.store.service.StoreException;
+import net.sf.joafip.store.service.proxy.StaticProxyCallBack;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+@SuppressWarnings("PMD")
+@NotStorableClass
+@StorableAccess
+public class AbstractInserter extends AbstractPerfService {
+
+ private static final File FILE_FOR_LUC = new File(RUNTIME_DIR
+ + "/forLuc.txt");
+
+ public static final File MEM_BIN = new File(RUNTIME_DIR + "/mem.bin");
+
+ private static final File MEM2_BIN = new File(RUNTIME_DIR + "/mem2.bin");
+
+ private static final boolean MEM_INSPECT = false;
+
+ private static final boolean OBJ_MEM_SIZE = false;
+
+ private MemInspector memInspector;
+
+ private boolean markNew;
+
+ private int pageSetSize;
+
+ private int readCacheMapSize;
+
+ private int writeCacheMapSize;
+
+ private int freePageRootNodeSize;
+
+ private int usedPageRootNodeSize;
+
+ public AbstractInserter(final String pathName)
+ throws FilePersistenceException,
+ FilePersistenceInvalidClassException,
+ FilePersistenceNotSerializableException,
+ FilePersistenceClassNotFoundException,
+ FilePersistenceDataCorruptedException, StoreClassNotFoundException,
+ FilePersistenceTooBigForSerializationException {
+ super(pathName);
+ }
+
+ protected void run(final int numberOfItem) throws FilePersistenceException,
+ StoreException, FilePersistenceClassNotFoundException,
+ FilePersistenceInvalidClassException,
+ FilePersistenceDataCorruptedException,
+ FilePersistenceNotSerializableException, MemInspectorException,
+ IOException, SecurityException, IllegalArgumentException,
+ NoSuchFieldException, IllegalAccessException,
+ FilePersistenceTooBigForSerializationException {
+ final Runtime runtime = Runtime.getRuntime();
+ final MemInspector memInspectorForMemory = new MemInspector();
+ addTemplate();
+ long maxMemUse = 0;
+ long maxMemUse2 = 0;
+ pageSetSize = 0;
+ readCacheMapSize = 0;
+ writeCacheMapSize = 0;
+ freePageRootNodeSize = 0;
+ usedPageRootNodeSize = 0;
+ final IDataAccessSession session = filePersistence
+ .createDataAccessSession();
+ initMemInspector();
+ session.open();
+ initializeByItemDuration();
+ boolean added = false;
+ long duration = 0;
+ for (int identifier = 0; !added && identifier < numberOfItem + 1; identifier++) {
+ // final ItemTemplateList itemTemplateList =
+ // getItemTemplateList(session);
+ // final ItemTemplate itemTemplate;
+ // switch (identifier % 3) {
+ // case 0:
+ // itemTemplate = itemTemplateList.getItemTemplate(1);
+ // break;
+ // case 1:
+ // itemTemplate = itemTemplateList.getItemTemplate(2);
+ // break;
+ // case 2:
+ // itemTemplate = itemTemplateList.getItemTemplate(3);
+ // break;
+ // default:
+ // itemTemplate = null;
+ // }
+ addItem(session, identifier);
+
+ if (identifier % BATCH_SIZE == BATCH_SIZE - 1) {
+
+ final long startTime = System.currentTimeMillis();
+ session.closeAndWait(EnumFilePersistenceCloseAction.SAVE);
+ final long currentTime = System.currentTimeMillis();
+ System.gc();
+ added = checkAdded(byItemIndex);
+ duration += (currentTime - startTime);
+ final long byItem = duration * 1000 / (identifier + 1);
+ final long memUse = runtime.totalMemory()
+ - runtime.freeMemory();
+ byItemMem[byItemIndex] = (int) (memUse / 1024);
+ if (memUse > maxMemUse) {
+ maxMemUse = memUse;
+ }
+ byItemDuration[byItemIndex] = (int) byItem;
+ final StringBuilder builder = new StringBuilder();
+ builder.append('\n');
+ builder.append(duration);
+ builder.append(" mS ");
+ builder.append(identifier + 1);
+ builder.append(" appened, by item ");
+ builder.append(byItem);
+ builder.append(" µS\nmem used=");
+ builder.append(mem(memUse));
+ builder.append("\nmax= ");
+ builder.append(mem(maxMemUse));
+ if (OBJ_MEM_SIZE) {
+ final long memUse2 = memInspectorForMemory
+ .memoryUsed(filePersistence);
+ if (memUse2 > maxMemUse2) {// NOPMD
+ maxMemUse2 = memUse2;
+ }
+ byItemMem2[byItemIndex] = (int) (memUse2 / 1024);
+ builder.append("\n\nuse= ");
+ builder.append(mem(memUse2));
+ builder.append("\nmax= ");
+ builder.append(mem(maxMemUse2));
+ }
+ if (FILE_CACHE) {
+ builder.append("\npageSet size=");
+ builder.append(pageSetSize);
+ builder.append('/');
+ builder.append(NUMBER_OF_PAGE);
+ builder.append("\nreadCacheMapSize size=");
+ builder.append(readCacheMapSize);
+ builder.append("\nwriteCacheMapSize size=");
+ builder.append(writeCacheMapSize);
+ builder.append("\nfreePageRootNodeSize size=");
+ builder.append(freePageRootNodeSize);
+ builder.append("\nusedPageRootNodeSize size=");
+ builder.append(usedPageRootNodeSize);
+ }
+ builder.append("\nWO SIZE=");
+ builder.append(StaticProxyCallBack.size());
+ logger.info(builder.toString());
+ byItemIndex++;
+
+ session.open();
+ }
+ }
+
+ session.closeAndWait(EnumFilePersistenceCloseAction.SAVE);
+
+ session.open();
+ final ItemList itemList = getItemList(session);
+ itemList.removeItem(NUMBER_OF_ITEM);
+ session.closeAndWait(EnumFilePersistenceCloseAction.SAVE);
+
+ FILE_FOR_LUC.delete();
+
+ logSize(-1, duration);
+
+ // startTime = System.currentTimeMillis();
+ // final int numberGarbaged = filePersistence.garbageSweep();
+ // endTime = System.currentTimeMillis();
+ // duration = (endTime - startTime);
+ //
+ // logSize(numberGarbaged, duration);
+
+ ObjectOutputStream objectOutputStream = new ObjectOutputStream(
+ new FileOutputStream(DURATION_BIN));
+ objectOutputStream.writeObject(byItemDuration);
+ objectOutputStream.close();
+
+ objectOutputStream = new ObjectOutputStream(new FileOutputStream(
+ MEM_BIN));
+ objectOutputStream.writeObject(byItemMem);
+ objectOutputStream.close();
+
+ if (OBJ_MEM_SIZE) {
+ objectOutputStream = new ObjectOutputStream(new FileOutputStream(
+ MEM2_BIN));
+ objectOutputStream.writeObject(byItemMem2);
+ objectOutputStream.close();
+ }
+
+ if (added) {
+ ShowObjectTree.show("runtime/mem.bin");
+ }
+ }
+
+ protected void close() throws FilePersistenceException {
+ filePersistence.close();
+ }
+
+ private void initMemInspector() throws MemInspectorException {
+ if (MEM_INSPECT) {
+ memInspector = new MemInspector();
+ MemInspectorJoafipSetup.setup(memInspector);
+ // memInspector.inspect(this, false);
+ markNew = false;
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private boolean checkAdded(final int byItemIndex)
+ throws MemInspectorException, SecurityException,
+ NoSuchFieldException, IllegalArgumentException,
+ IllegalAccessException {
+ final boolean added;
+ if (MEM_INSPECT) {
+ if (markNew) {
+ memInspector.inspect(this, true);
+ added = memInspector.added();
+ if (added) {
+ memInspector.serialize(new File("runtime/mem.bin"));
+ }
+ } else {
+ memInspector.inspect(this, false);
+ markNew = byItemIndex >= 2;
+ added = false;
+ }
+ if (FILE_CACHE) {
+ final List<Object> list = memInspector
+ .getInstanceOfClass("net.sf.joafip.file.service.RandomAccessFileReadWriteCache");
+ if (list.size() != 1) {
+ throw new MemInspectorException(
+ "bad number of RandomAccessFileReadWriteCache instance: "
+ + list.size());
+ }
+ final Object fileCache = list.get(0);
+ Field field = RandomAccessFileReadWriteCache.class
+ .getDeclaredField("pageSet");
+ field.setAccessible(true);
+ final PLinkedTreeSet<Long> pageSet = (PLinkedTreeSet<Long>) field
+ .get(fileCache);
+ pageSetSize = pageSet.size();
+
+ field = RandomAccessFileReadWriteCache.class
+ .getDeclaredField("readCacheMap");
+ field.setAccessible(true);
+ final Map<Long, PageNode> readCacheMap = (Map<Long, PageNode>) field
+ .get(fileCache);
+ readCacheMapSize = readCacheMap.size();
+
+ field = RandomAccessFileReadWriteCache.class
+ .getDeclaredField("writeCacheMap");
+ field.setAccessible(true);
+ final Map<Long, PageNode> writeCacheMap = (Map<Long, PageNode>) field
+ .get(fileCache);
+ writeCacheMapSize = writeCacheMap.size();
+
+ field = RandomAccessFileReadWriteCache.class
+ .getDeclaredField("freePageRootNode");
+ field.setAccessible(true);
+ PageNode pageNode = (PageNode) field.get(fileCache);
+ freePageRootNodeSize = pageNodeListSize(pageNode);
+
+ field = RandomAccessFileReadWriteCache.class
+ .getDeclaredField("usedPageRootNode");
+ field.setAccessible(true);
+ pageNode = (PageNode) field.get(fileCache);
+ usedPageRootNodeSize = pageNodeListSize(pageNode);
+ }
+ } else {
+ added = false;
+ }
+ return added;
+ }
+
+ /**
+ * @param numberGarbaged
+ * @param duration
+ * @throws FilePersistenceException
+ * @throws FileNotFoundException
+ */
+ private void logSize(final int numberGarbaged, final long duration)
+ throws FilePersistenceException, FileNotFoundException {
+ PrintWriter writer;
+ writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
+ new FileOutputStream(FILE_FOR_LUC, true))));
+ String message;
+ message = "-----------------------";
+ printMessage(writer, message);
+
+ message = "nb of item=" + NUMBER_OF_ITEM;
+ printMessage(writer, message);
+ message = "batch size=" + BATCH_SIZE;
+ printMessage(writer, message);
+ message = "duration=" + duration + " mS";
+ printMessage(writer, message);
+
+ if (numberGarbaged >= 0) {
+ message = "garbaged=" + numberGarbaged;
+ printMessage(writer, message);
+ }
+ if (filePersistence.isGarbageManagement()) {
+ message = "to garbage=" + filePersistence.getNumberOfToGarbage();
+ printMessage(writer, message);
+ message = "garbage candidate="
+ + filePersistence.getNumberOfGarbageCandidate();
+ printMessage(writer, message);
+ }
+ message = "nb of data record="
+ + filePersistence.getNumberOfDataRecord();
+ printMessage(writer, message);
+ message = "nb of free record="
+ + filePersistence.getNumberOfFreeRecord();
+ printMessage(writer, message);
+ message = "used size=" + filePersistence.usedSize();
+ printMessage(writer, message);
+ message = "free size=" + filePersistence.freeSize();
+ printMessage(writer, message);
+ message = "heap size=" + filePersistence.totalSize();
+ printMessage(writer, message);
+ writer.close();
+ }
+
+ private int pageNodeListSize(final PageNode pageNode) {
+ int size = 0;
+ PageNode current = pageNode;
+ while (current != null) {
+ size++;
+ current = current.next;
+ }
+ return size;
+ }
+
+ private String mem(final long value) {
+ final long ktot = value / 1024;
+ final int b = (int) (value % 1024);
+ final int k = (int) (ktot % 1024);
+ final long mtot = ktot / 1024;
+ final long m = mtot % 1024;
+ final long gtot = mtot / 1024;
+ return String.format("%03d g %04d m %04d k %04d b", gtot, m, k, b);
+ }
+
+ /**
+ * @param writer
+ * @param message
+ */
+ private void printMessage(final PrintWriter writer, final String message) {
+ logger.info(message);
+ writer.println(message);
+ }
+
+ /**
+ * @param session
+ * @param identifier
+ * @throws FilePersistenceException
+ */
+ private void addItem(final IDataAccessSession session, final int identifier)
+ throws FilePersistenceException {
+ try {
+ final Item item = new Item(identifier, null/* itemTemplate */,
+ "item" + identifier);
+ final ItemList itemList = getItemList(session);
+ itemList.addItem(item);
+ } catch (final RuntimeException exception) {
+ logger.fatal("adding item " + identifier, exception);
+ throw exception;
+ }
+ }
+
+ private void addTemplate() throws FilePersistenceException,
+ FilePersistenceClassNotFoundException,
+ FilePersistenceInvalidClassException,
+ FilePersistenceDataCorruptedException,
+ FilePersistenceNotSerializableException,
+ FilePersistenceTooBigForSerializationException {
+ final ItemTemplate itemTemplate1 = new ItemTemplate(1, "template1");
+ final ItemTemplate itemTemplate2 = new ItemTemplate(2, "template2");
+ final ItemTemplate itemTemplate3 = new ItemTemplate(3, "template3");
+ final IDataAccessSession session = filePersistence
+ .createDataAccessSession();
+ session.open();
+ final ItemTemplateList itemTemplateList = getItemTemplateList(session);
+ itemTemplateList.addItemTemplate(itemTemplate1);
+ itemTemplateList.addItemTemplate(itemTemplate2);
+ itemTemplateList.addItemTemplate(itemTemplate3);
+ session.closeAndWait(EnumFilePersistenceCloseAction.SAVE);
+ }
+
+ protected void export(final String directoryName)
+ throws FilePersistenceException,
+ FilePersistenceClassNotFoundException,
+ FilePersistenceInvalidClassException,
+ FilePersistenceDataCorruptedException,
+ FilePersistenceNotSerializableException,
+ FilePersistenceTooBigForSerializationException {
+ filePersistence.xmlExport(directoryName, directoryName + "/tmp", false);
+ }
+}
Modified: trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/AbstractPerfService.java
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/AbstractPerfService.java 2011-10-01 16:45:37 UTC (rev 2910)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/AbstractPerfService.java 2011-10-01 17:08:48 UTC (rev 2911)
@@ -41,13 +41,13 @@
@StorableAccess
public class AbstractPerfService {
+ protected final JoafipLogger logger = JoafipLogger.getLogger(getClass());// NOPMD
+
protected static final String RUNTIME_DIR = "runtime_perf";
public static final File DURATION_BIN = new File(RUNTIME_DIR
+ "/duration.bin");
- protected final JoafipLogger logger = JoafipLogger.getLogger(getClass());// NOPMD
-
protected static final int BATCH_SIZE = 1000;
protected static final int NUMBER_OF_ITEM = 1000000;
@@ -77,7 +77,8 @@
protected int byItemIndex;
- public AbstractPerfService() throws FilePersistenceException,
+ public AbstractPerfService(final String pathName)
+ throws FilePersistenceException,
FilePersistenceInvalidClassException,
FilePersistenceNotSerializableException,
FilePersistenceClassNotFoundException,
@@ -86,7 +87,7 @@
super();
final FilePersistenceBuilder builder = new FilePersistenceBuilder();
try {
- builder.setPathName(RUNTIME_DIR);
+ builder.setPathName(pathName);
builder.setRemoveFiles(false);
builder.setProxyMode(true);
builder.setCrashSafeMode(CRASH_SAFE_MODE);
Added: trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/AbstractSearcher.java
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/AbstractSearcher.java (rev 0)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/AbstractSearcher.java 2011-10-01 17:08:48 UTC (rev 2911)
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2011 Luc Peuvrier
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (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.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * 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 net.sf.joafip.performance.items.service;
+
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.util.LinkedList;
+import java.util.List;
+
+import net.sf.joafip.entity.EnumFilePersistenceCloseAction;
+import net.sf.joafip.logger.JoafipLogger;
+import net.sf.joafip.performance.items.entity.ItemList;
+import net.sf.joafip.service.FilePersistenceClassNotFoundException;
+import net.sf.joafip.service.FilePersistenceDataCorruptedException;
+import net.sf.joafip.service.FilePersistenceException;
+import net.sf.joafip.service.FilePersistenceInvalidClassException;
+import net.sf.joafip.service.FilePersistenceNotSerializableException;
+import net.sf.joafip.service.FilePersistenceTooBigForSerializationException;
+import net.sf.joafip.service.IDataAccessSession;
+import net.sf.joafip.store.service.StoreClassNotFoundException;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+public class AbstractSearcher extends AbstractPerfService {
+
+ private final JoafipLogger logger = JoafipLogger.getLogger(getClass());
+
+ public AbstractSearcher(final String pathName)
+ throws FilePersistenceException,
+ FilePersistenceInvalidClassException,
+ FilePersistenceNotSerializableException,
+ FilePersistenceClassNotFoundException,
+ FilePersistenceDataCorruptedException, StoreClassNotFoundException,
+ FilePersistenceTooBigForSerializationException {
+ super(pathName);
+ }
+
+ protected void run() throws FilePersistenceException,
+ FilePersistenceClassNotFoundException,
+ FilePersistenceInvalidClassException,
+ FilePersistenceDataCorruptedException,
+ FilePersistenceNotSerializableException, FileNotFoundException,
+ IOException, FilePersistenceTooBigForSerializationException {
+
+ long maxSearchTime = Long.MIN_VALUE;
+ long minSearchTime = Long.MAX_VALUE;
+ final long startTime = System.currentTimeMillis();
+ final IDataAccessSession session = filePersistence
+ .createDataAccessSession();
+ session.open();
+ initializeByItemDuration();
+ int missingCount = 0;
+ final List<Integer> missingList = new LinkedList<Integer>();
+ for (int identifier = 0; identifier < NUMBER_OF_ITEM; identifier++) {
+ final ItemList itemList = getItemList(session);
+ final long startSearchTime = System.currentTimeMillis();
+ if (itemList.get(identifier) == null) {
+ // throw new
+ // IllegalStateException("missing item for identifier "
+ // + identifier);
+ logger.info("missing item for identifier " + identifier);
+ missingCount++;
+ if (missingCount < 20) {
+ missingList.add(identifier);
+ }
+ }
+ final long currentTime = System.currentTimeMillis();
+ final long searchDuration = currentTime - startSearchTime;
+ if (searchDuration > maxSearchTime) {
+ maxSearchTime = searchDuration;
+ }
+ if (searchDuration < minSearchTime) {
+ minSearchTime = searchDuration;
+ }
+ if (identifier % BATCH_SIZE == BATCH_SIZE - 1) {
+ session.close(EnumFilePersistenceCloseAction.DO_NOT_SAVE);
+ session.open();
+ final long duration = (currentTime - startTime);
+ final long byItem = duration * 1000 / (identifier + 1);
+ byItemDuration[byItemIndex++] = (int) byItem;
+ logger.info(duration + " mS " + (identifier + 1)
+ + " found, by item " + byItem + " uS");
+ }
+ }
+ session.close(EnumFilePersistenceCloseAction.DO_NOT_SAVE);
+ final long endTime = System.currentTimeMillis();
+ logger.info("min search time " + minSearchTime);
+ logger.info("max search time " + maxSearchTime);
+ logger.info((endTime - startTime) + " mS for " + NUMBER_OF_ITEM
+ + " items");
+ logger.info("missing count=" + missingCount);
+ logger.info("missing list=" + missingList.toString());
+ final ObjectOutputStream objectOutputStream = new ObjectOutputStream(
+ new FileOutputStream(DURATION_BIN));
+ objectOutputStream.writeObject(byItemDuration);
+ objectOutputStream.close();
+ }
+}
Modified: trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/Exporter.java
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/Exporter.java 2011-10-01 16:45:37 UTC (rev 2910)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/Exporter.java 2011-10-01 17:08:48 UTC (rev 2911)
@@ -64,12 +64,6 @@
FilePersistenceClassNotFoundException,
FilePersistenceDataCorruptedException,
FilePersistenceTooBigForSerializationException {
- // final FilePersistence filePersistence = new FilePersistence(1, null,
- // "runtime_perf",
- // /**/false/* do not remove files */,
- // /**/1024/* PAGE_SIZE */, 1024/* NUMBER_OF_PAGE */,
- // /**/false/* GARBAGE */,
- // /**/false/* CRASH_SAFE_MODE */);
final FilePersistenceBuilder builder = new FilePersistenceBuilder();
builder.setPathName("runtime_perf");
builder.setFileCache(/**/1024/* PAGE_SIZE */, 1024/* NUMBER_OF_PAGE */);
Modified: trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/Garbage.java
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/Garbage.java 2011-10-01 16:45:37 UTC (rev 2910)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/Garbage.java 2011-10-01 17:08:48 UTC (rev 2911)
@@ -38,20 +38,20 @@
public static void main(final String[] args) {
Garbage garbage;
try {
- garbage = new Garbage();
+ garbage = new Garbage(RUNTIME_DIR);
garbage.execute();
} catch (final Throwable throwable) {// NOPMD catch all
LOGGER.fatal("error", throwable);
}
}
- public Garbage() throws FilePersistenceException,
+ public Garbage(final String pathName) throws FilePersistenceException,
FilePersistenceInvalidClassException,
FilePersistenceNotSerializableException,
FilePersistenceClassNotFoundException,
FilePersistenceDataCorruptedException, StoreClassNotFoundException,
FilePersistenceTooBigForSerializationException {
- super();
+ super(pathName);
}
private long displayTime;
Added: trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/ImportSearcher.java
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/ImportSearcher.java (rev 0)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/ImportSearcher.java 2011-10-01 17:08:48 UTC (rev 2911)
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2007 Luc Peuvrier
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (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.gnu.org/licenses/lgpl.html
+ *
+ * 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 net.sf.joafip.performance.items.service;
+
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.StorableAccess;
+import net.sf.joafip.logger.JoafipLogger;
+import net.sf.joafip.service.FilePersistenceClassNotFoundException;
+import net.sf.joafip.service.FilePersistenceDataCorruptedException;
+import net.sf.joafip.service.FilePersistenceException;
+import net.sf.joafip.service.FilePersistenceInvalidClassException;
+import net.sf.joafip.service.FilePersistenceNotSerializableException;
+import net.sf.joafip.service.FilePersistenceTooBigForSerializationException;
+import net.sf.joafip.store.service.StoreClassNotFoundException;
+
+@NotStorableClass
+@StorableAccess
+public class ImportSearcher extends AbstractSearcher {
+
+ private static final JoafipLogger LOGGER = JoafipLogger
+ .getLogger(ImportSearcher.class);
+
+ public ImportSearcher(final String pathName)
+ throws FilePersistenceException,
+ FilePersistenceInvalidClassException,
+ FilePersistenceNotSerializableException,
+ FilePersistenceClassNotFoundException,
+ FilePersistenceDataCorruptedException, StoreClassNotFoundException,
+ FilePersistenceTooBigForSerializationException {
+ super(pathName);
+ }
+
+ public static void main(final String[] args) {
+ ImportSearcher searcher;
+ try {
+ searcher = new ImportSearcher("runtime_perf/from_import");
+ searcher.run();
+ } catch (final Throwable throwable) {// NOPMD catch all
+ LOGGER.fatal("error", throwable);
+ }
+ }
+}
Added: trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/Importer.java
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/Importer.java (rev 0)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/Importer.java 2011-10-01 17:08:48 UTC (rev 2911)
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2011 Luc Peuvrier
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (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.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * 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 net.sf.joafip.performance.items.service;
+
+import net.sf.joafip.logger.JoafipLogger;
+import net.sf.joafip.service.FilePersistenceBuilder;
+import net.sf.joafip.service.FilePersistenceClassNotFoundException;
+import net.sf.joafip.service.FilePersistenceDataCorruptedException;
+import net.sf.joafip.service.FilePersistenceException;
+import net.sf.joafip.service.FilePersistenceInvalidClassException;
+import net.sf.joafip.service.FilePersistenceNotSerializableException;
+import net.sf.joafip.service.FilePersistenceTooBigForSerializationException;
+import net.sf.joafip.service.IFilePersistence;
+import net.sf.joafip.store.service.export_import.in.IImportListener;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+public final class Importer implements IImportListener {
+
+ private final static JoafipLogger LOGGER = JoafipLogger
+ .getLogger(Importer.class);
+
+ private long startTime;
+
+ private long numberOfImported;// NOPMD
+
+ public static void main(final String[] args) {
+ try {
+ final Importer exporter = new Importer();
+ exporter.run();
+ } catch (final Throwable throwable) {// NOPMD catch all
+ LOGGER.fatal("error", throwable);
+ }
+ }
+
+ private Importer() {
+ super();
+ }
+
+ private void run() throws FilePersistenceException,
+ FilePersistenceInvalidClassException,
+ FilePersistenceNotSerializableException,
+ FilePersistenceClassNotFoundException,
+ FilePersistenceDataCorruptedException,
+ FilePersistenceTooBigForSerializationException {
+ final FilePersistenceBuilder builder = new FilePersistenceBuilder();
+ builder.setPathName("runtime_perf/from_import");
+ builder.setFileCache(/**/1024/* PAGE_SIZE */, 1024/* NUMBER_OF_PAGE */);
+ builder.setProxyMode(true);
+ builder.setRemoveFiles(false);
+ builder.setGarbageManagement(false);
+ builder.setCrashSafeMode(false);
+ builder.setRemoveFiles(true);
+ final IFilePersistence filePersistence = builder.build();
+
+ filePersistence.setImportListener(this);
+ startTime = System.currentTimeMillis();
+ filePersistence.xmlImport("runtime_perf/export");
+ System.out.println(numberOfImported + " imported, duration "// NOPMD
+ + (System.currentTimeMillis() - startTime));
+ filePersistence.close();
+ }
+
+ @Override
+ public void numberOfImported(final long numberOfImported) {
+ this.numberOfImported = numberOfImported;
+ if (numberOfImported % 100 == 0) {
+ final double byRecordDuration = (double) (System
+ .currentTimeMillis() - startTime)
+ / (double) numberOfImported;
+ System.out.println("imported " + numberOfImported// NOPMD
+ + " bye record duration " + byRecordDuration + " mS");
+ }
+ }
+}
Modified: trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/Inserter.java
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/Inserter.java 2011-10-01 16:45:37 UTC (rev 2910)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/Inserter.java 2011-10-01 17:08:48 UTC (rev 2911)
@@ -1,5 +1,5 @@
/*
- * Copyright 2007 Luc Peuvrier
+ * Copyright 2011 Luc Peuvrier
*
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
* Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
@@ -16,84 +16,34 @@
*/
package net.sf.joafip.performance.items.service;//NOPMD
-import java.io.BufferedWriter;
import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.ObjectOutputStream;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.lang.reflect.Field;
-import java.util.List;
-import java.util.Map;
import net.sf.joafip.NotStorableClass;
import net.sf.joafip.StorableAccess;
-import net.sf.joafip.entity.EnumFilePersistenceCloseAction;
-import net.sf.joafip.file.entity.PageNode;
-import net.sf.joafip.file.service.RandomAccessFileReadWriteCache;
-import net.sf.joafip.java.util.PLinkedTreeSet;
import net.sf.joafip.logger.JoafipLogger;
-import net.sf.joafip.meminspector.service.MemInspectorException;
-import net.sf.joafip.meminspector.service.inspect.MemInspector;
-import net.sf.joafip.meminspector.service.show.ShowObjectTree;
-import net.sf.joafip.performance.items.entity.Item;
-import net.sf.joafip.performance.items.entity.ItemList;
-import net.sf.joafip.performance.items.entity.ItemTemplate;
-import net.sf.joafip.performance.items.entity.ItemTemplateList;
import net.sf.joafip.service.FilePersistenceClassNotFoundException;
import net.sf.joafip.service.FilePersistenceDataCorruptedException;
import net.sf.joafip.service.FilePersistenceException;
import net.sf.joafip.service.FilePersistenceInvalidClassException;
import net.sf.joafip.service.FilePersistenceNotSerializableException;
import net.sf.joafip.service.FilePersistenceTooBigForSerializationException;
-import net.sf.joafip.service.IDataAccessSession;
-import net.sf.joafip.service.MemInspectorJoafipSetup;
import net.sf.joafip.store.service.StoreClassNotFoundException;
-import net.sf.joafip.store.service.StoreException;
-import net.sf.joafip.store.service.proxy.StaticProxyCallBack;
@SuppressWarnings("PMD")
@NotStorableClass
@StorableAccess
-public class Inserter extends AbstractPerfService {
+public class Inserter extends AbstractInserter {
private static final JoafipLogger LOGGER = JoafipLogger
.getLogger(Inserter.class);
- private static final File FILE_FOR_LUC = new File(RUNTIME_DIR
- + "/forLuc.txt");
-
- public static final File MEM_BIN = new File(RUNTIME_DIR + "/mem.bin");
-
- private static final File MEM2_BIN = new File(RUNTIME_DIR + "/mem2.bin");
-
- private static final boolean MEM_INSPECT = false;
-
- private static final boolean OBJ_MEM_SIZE = false;
-
- private MemInspector memInspector;
-
- private boolean markNew;
-
- private int pageSetSize;
-
- private int readCacheMapSize;
-
- private int writeCacheMapSize;
-
- private int freePageRootNodeSize;
-
- private int usedPageRootNodeSize;
-
- public Inserter() throws FilePersistenceException,
+ public Inserter(final String pathName) throws FilePersistenceException,
FilePersistenceInvalidClassException,
FilePersistenceNotSerializableException,
FilePersistenceClassNotFoundException,
FilePersistenceDataCorruptedException, StoreClassNotFoundException,
FilePersistenceTooBigForSerializationException {
- super();
+ super(pathName);
}
public static void main(final String[] args) {
@@ -105,347 +55,11 @@
dataDirectory.mkdirs();
Inserter inserter;
try {
- inserter = new Inserter();
- inserter.run();
+ inserter = new Inserter(RUNTIME_DIR);
+ inserter.run(NUMBER_OF_ITEM);
+ inserter.close();
} catch (final Throwable throwable) {// NOPMD catch all
LOGGER.fatal("error", throwable);
}
}
-
- private void run() throws FilePersistenceException, StoreException,
- FilePersistenceClassNotFoundException,
- FilePersistenceInvalidClassException,
- FilePersistenceDataCorruptedException,
- FilePersistenceNotSerializableException, MemInspectorException,
- IOException, SecurityException, IllegalArgumentException,
- NoSuchFieldException, IllegalAccessException,
- FilePersistenceTooBigForSerializationException {
- final Runtime runtime = Runtime.getRuntime();
- final MemInspector memInspectorForMemory = new MemInspector();
- addTemplate();
- long maxMemUse = 0;
- long maxMemUse2 = 0;
- pageSetSize = 0;
- readCacheMapSize = 0;
- writeCacheMapSize = 0;
- freePageRootNodeSize = 0;
- usedPageRootNodeSize = 0;
- final IDataAccessSession session = filePersistence
- .createDataAccessSession();
- initMemInspector();
- session.open();
- initializeByItemDuration();
- boolean added = false;
- long duration = 0;
- for (int identifier = 0; !added && identifier < NUMBER_OF_ITEM + 1; identifier++) {
- // final ItemTemplateList itemTemplateList =
- // getItemTemplateList(session);
- // final ItemTemplate itemTemplate;
- // switch (identifier % 3) {
- // case 0:
- // itemTemplate = itemTemplateList.getItemTemplate(1);
- // break;
- // case 1:
- // itemTemplate = itemTemplateList.getItemTemplate(2);
- // break;
- // case 2:
- // itemTemplate = itemTemplateList.getItemTemplate(3);
- // break;
- // default:
- // itemTemplate = null;
- // }
- addItem(session, identifier);
-
- if (identifier % BATCH_SIZE == BATCH_SIZE - 1) {
-
- final long startTime = System.currentTimeMillis();
- session.closeAndWait(EnumFilePersistenceCloseAction.SAVE);
- final long currentTime = System.currentTimeMillis();
- System.gc();
- added = checkAdded(byItemIndex);
- duration += (currentTime - startTime);
- final long byItem = duration * 1000 / (identifier + 1);
- final long memUse = runtime.totalMemory()
- - runtime.freeMemory();
- byItemMem[byItemIndex] = (int) (memUse / 1024);
- if (memUse > maxMemUse) {
- maxMemUse = memUse;
- }
- byItemDuration[byItemIndex] = (int) byItem;
- final StringBuilder builder = new StringBuilder();
- builder.append('\n');
- builder.append(duration);
- builder.append(" mS ");
- builder.append(identifier + 1);
- builder.append(" appened, by item ");
- builder.append(byItem);
- builder.append(" µS\nmem used=");
- builder.append(mem(memUse));
- builder.append("\nmax= ");
- builder.append(mem(maxMemUse));
- if (OBJ_MEM_SIZE) {
- final long memUse2 = memInspectorForMemory
- .memoryUsed(filePersistence);
- if (memUse2 > maxMemUse2) {// NOPMD
- maxMemUse2 = memUse2;
- }
- byItemMem2[byItemIndex] = (int) (memUse2 / 1024);
- builder.append("\n\nuse= ");
- builder.append(mem(memUse2));
- builder.append("\nmax= ");
- builder.append(mem(maxMemUse2));
- }
- if (FILE_CACHE) {
- builder.append("\npageSet size=");
- builder.append(pageSetSize);
- builder.append('/');
- builder.append(NUMBER_OF_PAGE);
- builder.append("\nreadCacheMapSize size=");
- builder.append(readCacheMapSize);
- builder.append("\nwriteCacheMapSize size=");
- builder.append(writeCacheMapSize);
- builder.append("\nfreePageRootNodeSize size=");
- builder.append(freePageRootNodeSize);
- builder.append("\nusedPageRootNodeSize size=");
- builder.append(usedPageRootNodeSize);
- }
- builder.append("\nWO SIZE=");
- builder.append(StaticProxyCallBack.size());
- LOGGER.info(builder.toString());
- byItemIndex++;
-
- session.open();
- }
- }
-
- session.closeAndWait(EnumFilePersistenceCloseAction.SAVE);
-
- session.open();
- final ItemList itemList = getItemList(session);
- itemList.removeItem(NUMBER_OF_ITEM);
- session.closeAndWait(EnumFilePersistenceCloseAction.SAVE);
-
- FILE_FOR_LUC.delete();
-
- logSize(-1, duration);
-
- // startTime = System.currentTimeMillis();
- // final int numberGarbaged = filePersistence.garbageSweep();
- // endTime = System.currentTimeMillis();
- // duration = (endTime - startTime);
- //
- // logSize(numberGarbaged, duration);
-
- filePersistence.close();
-
- ObjectOutputStream objectOutputStream = new ObjectOutputStream(
- new FileOutputStream(DURATION_BIN));
- objectOutputStream.writeObject(byItemDuration);
- objectOutputStream.close();
-
- objectOutputStream = new ObjectOutputStream(new FileOutputStream(
- MEM_BIN));
- objectOutputStream.writeObject(byItemMem);
- objectOutputStream.close();
-
- if (OBJ_MEM_SIZE) {
- objectOutputStream = new ObjectOutputStream(new FileOutputStream(
- MEM2_BIN));
- objectOutputStream.writeObject(byItemMem2);
- objectOutputStream.close();
- }
-
- if (added) {
- ShowObjectTree.show("runtime/mem.bin");
- }
- }
-
- private void initMemInspector() throws MemInspectorException {
- if (MEM_INSPECT) {
- memInspector = new MemInspector();
- MemInspectorJoafipSetup.setup(memInspector);
- // memInspector.inspect(this, false);
- markNew = false;
- }
- }
-
- @SuppressWarnings("unchecked")
- private boolean checkAdded(final int byItemIndex)
- throws MemInspectorException, SecurityException,
- NoSuchFieldException, IllegalArgumentException,
- IllegalAccessException {
- final boolean added;
- if (MEM_INSPECT) {
- if (markNew) {
- memInspector.inspect(this, true);
- added = memInspector.added();
- if (added) {
- memInspector.serialize(new File("runtime/mem.bin"));
- }
- } else {
- memInspector.inspect(this, false);
- markNew = byItemIndex >= 2;
- added = false;
- }
- if (FILE_CACHE) {
- final List<Object> list = memInspector
- .getInstanceOfClass("net.sf.joafip.file.service.RandomAccessFileReadWriteCache");
- if (list.size() != 1) {
- throw new MemInspectorException(
- "bad number of RandomAccessFileReadWriteCache instance: "
- + list.size());
- }
- final Object fileCache = list.get(0);
- Field field = RandomAccessFileReadWriteCache.class
- .getDeclaredField("pageSet");
- field.setAccessible(true);
- final PLinkedTreeSet<Long> pageSet = (PLinkedTreeSet<Long>) field
- .get(fileCache);
- pageSetSize = pageSet.size();
-
- field = RandomAccessFileReadWriteCache.class
- .getDeclaredField("readCacheMap");
- field.setAccessible(true);
- final Map<Long, PageNode> readCacheMap = (Map<Long, PageNode>) field
- .get(fileCache);
- readCacheMapSize = readCacheMap.size();
-
- field = RandomAccessFileReadWriteCache.class
- .getDeclaredField("writeCacheMap");
- field.setAccessible(true);
- final Map<Long, PageNode> writeCacheMap = (Map<Long, PageNode>) field
- .get(fileCache);
- writeCacheMapSize = writeCacheMap.size();
-
- field = RandomAccessFileReadWriteCache.class
- .getDeclaredField("freePageRootNode");
- field.setAccessible(true);
- PageNode pageNode = (PageNode) field.get(fileCache);
- freePageRootNodeSize = pageNodeListSize(pageNode);
-
- field = RandomAccessFileReadWriteCache.class
- .getDeclaredField("usedPageRootNode");
- field.setAccessible(true);
- pageNode = (PageNode) field.get(fileCache);
- usedPageRootNodeSize = pageNodeListSize(pageNode);
- }
- } else {
- added = false;
- }
- return added;
- }
-
- private int pageNodeListSize(final PageNode pageNode) {
- int size = 0;
- PageNode current = pageNode;
- while (current != null) {
- size++;
- current = current.next;
- }
- return size;
- }
-
- private String mem(final long value) {
- final long ktot = value / 1024;
- final int b = (int) (value % 1024);
- final int k = (int) (ktot % 1024);
- final long mtot = ktot / 1024;
- final long m = mtot % 1024;
- final long gtot = mtot / 1024;
- return String.format("%03d g %04d m %04d k %04d b", gtot, m, k, b);
- }
-
- /**
- * @param numberGarbaged
- * @param duration
- * @throws FilePersistenceException
- * @throws FileNotFoundException
- */
- private void logSize(final int numberGarbaged, final long duration)
- throws FilePersistenceException, FileNotFoundException {
- PrintWriter writer;
- writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
- new FileOutputStream(FILE_FOR_LUC, true))));
- String message;
- message = "-----------------------";
- printMessage(writer, message);
-
- message = "nb of item=" + NUMBER_OF_ITEM;
- printMessage(writer, message);
- message = "batch size=" + BATCH_SIZE;
- printMessage(writer, message);
- message = "duration=" + duration + " mS";
- printMessage(writer, message);
-
- if (numberGarbaged >= 0) {
- message = "garbaged=" + numberGarbaged;
- printMessage(writer, message);
- }
- if (filePersistence.isGarbageManagement()) {
- message = "to garbage=" + filePersistence.getNumberOfToGarbage();
- printMessage(writer, message);
- message = "garbage candidate="
- + filePersistence.getNumberOfGarbageCandidate();
- printMessage(writer, message);
- }
- message = "nb of data record="
- + filePersistence.getNumberOfDataRecord();
- printMessage(writer, message);
- message = "nb of free record="
- + filePersistence.getNumberOfFreeRecord();
- printMessage(writer, message);
- message = "used size=" + filePersistence.usedSize();
- printMessage(writer, message);
- message = "free size=" + filePersistence.freeSize();
- printMessage(writer, message);
- message = "heap size=" + filePersistence.totalSize();
- printMessage(writer, message);
- writer.close();
- }
-
- /**
- * @param writer
- * @param message
- */
- private void printMessage(final PrintWriter writer, final String message) {
- LOGGER.info(message);
- writer.println(message);
- }
-
- /**
- * @param session
- * @param identifier
- * @throws FilePersistenceException
- */
- private void addItem(final IDataAccessSession session, final int identifier)
- throws FilePersistenceException {
- try {
- final Item item = new Item(identifier, null/* itemTemplate */,
- "item" + identifier);
- final ItemList itemList = getItemList(session);
- itemList.addItem(item);
- } catch (final RuntimeException exception) {
- LOGGER.fatal("adding item " + identifier, exception);
- throw exception;
- }
- }
-
- private void addTemplate() throws FilePersistenceException,
- FilePersistenceClassNotFoundException,
- FilePersistenceInvalidClassException,
- FilePersistenceDataCorruptedException,
- FilePersistenceNotSerializableException,
- FilePersistenceTooBigForSerializationException {
- final ItemTemplate itemTemplate1 = new ItemTemplate(1, "template1");
- final ItemTemplate itemTemplate2 = new ItemTemplate(2, "template2");
- final ItemTemplate itemTemplate3 = new ItemTemplate(3, "template3");
- final IDataAccessSession session = filePersistence
- .createDataAccessSession();
- session.open();
- final ItemTemplateList itemTemplateList = getItemTemplateList(session);
- itemTemplateList.addItemTemplate(itemTemplate1);
- itemTemplateList.addItemTemplate(itemTemplate2);
- itemTemplateList.addItemTemplate(itemTemplate3);
- session.closeAndWait(EnumFilePersistenceCloseAction.SAVE);
- }
}
Added: trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/InserterFewInsertAndExport.java
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/InserterFewInsertAndExport.java (rev 0)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/InserterFewInsertAndExport.java 2011-10-01 17:08:48 UTC (rev 2911)
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2011 Luc Peuvrier
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (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.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * 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 net.sf.joafip.performance.items.service;//NOPMD
+
+import java.io.File;
+
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.StorableAccess;
+import net.sf.joafip.logger.JoafipLogger;
+import net.sf.joafip.service.FilePersistenceClassNotFoundException;
+import net.sf.joafip.service.FilePersistenceDataCorruptedException;
+import net.sf.joafip.service.FilePersistenceException;
+import net.sf.joafip.service.FilePersistenceInvalidClassException;
+import net.sf.joafip.service.FilePersistenceNotSerializableException;
+import net.sf.joafip.service.FilePersistenceTooBigForSerializationException;
+import net.sf.joafip.store.service.StoreClassNotFoundException;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+@SuppressWarnings("PMD")
+@NotStorableClass
+@StorableAccess
+public class InserterFewInsertAndExport extends AbstractInserter {
+
+ private static final JoafipLogger LOGGER = JoafipLogger
+ .getLogger(InserterFewInsertAndExport.class);
+
+ public InserterFewInsertAndExport(final String pathName)
+ throws FilePersistenceException,
+ FilePersistenceInvalidClassException,
+ FilePersistenceNotSerializableException,
+ FilePersistenceClassNotFoundException,
+ FilePersistenceDataCorruptedException, StoreClassNotFoundException,
+ FilePersistenceTooBigForSerializationException {
+ super(pathName);
+ }
+
+ public static void main(final String[] args) {
+ /* remove existing data */
+ final File dataDirectory = new File("runtime");
+ for (final File file : dataDirectory.listFiles()) {
+ file.delete();
+ }
+ dataDirectory.mkdirs();
+ InserterFewInsertAndExport inserter;
+ try {
+ inserter = new InserterFewInsertAndExport("runtime");
+ inserter.run(1);
+ inserter.export("runtime");
+ inserter.close();
+ } catch (final Throwable throwable) {// NOPMD catch all
+ LOGGER.fatal("error", throwable);
+ }
+ }
+}
Added: trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/MainExportScanner.java
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/MainExportScanner.java (rev 0)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/MainExportScanner.java 2011-10-01 17:08:48 UTC (rev 2911)
@@ -0,0 +1,241 @@
+/*
+ * Copyright 2011 Luc Peuvrier
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (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.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * 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 net.sf.joafip.performance.items.service;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Arrays;
+import java.util.Deque;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Set;
+import java.util.TreeSet;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.logger.JoafipLogger;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.XMLReader;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+@NotStorableClass
+public final class MainExportScanner implements ErrorHandler, ContentHandler {
+
+ private static final JoafipLogger LOGGER = JoafipLogger
+ .getLogger(MainExportScanner.class);
+
+ private final Deque<String> que = new LinkedList<String>();
+
+ private final Deque<String> attrQue = new LinkedList<String>();
+
+ private final Set<Integer> valueSet = new TreeSet<Integer>();
+
+ private int total;
+
+ private int count;
+
+ private PrintWriter printWriter;
+
+ private MainExportScanner() {
+ super();
+ }
+
+ public static void main(final String[] args) {
+ try {
+ final MainExportScanner main = new MainExportScanner();
+ main.run();
+ } catch (Exception exception) {
+ LOGGER.error("execution failure", exception);
+ }
+ }
+
+ private void run() throws ParserConfigurationException, SAXException,
+ IOException {
+ printWriter = new PrintWriter(new File(
+ "runtime_perf/export/missing.txt"));
+ total = 0;
+ count = 0;
+ valueSet.add(108738);
+ valueSet.add(118200);
+ valueSet.add(132948);
+ valueSet.add(142808);
+ valueSet.add(165872);
+
+ final SAXParserFactory factory = SAXParserFactory.newInstance();
+ factory.setValidating(false);
+ factory.setNamespaceAware(true);
+ final SAXParser parser = factory.newSAXParser();
+ final XMLReader reader = parser.getXMLReader();
+ reader.setErrorHandler(this);
+ reader.setContentHandler(this);
+ reader.parse(new InputSource("runtime_perf/export/export.xml"));
+ System.out.println("count=" + count + " total=" + total);// NOPMD
+ printWriter.close();
+ }
+
+ @Override
+ public void warning(final SAXParseException exception) throws SAXException {
+ LOGGER.warn("sax error", exception);
+ }
+
+ @Override
+ public void error(final SAXParseException exception) throws SAXException {
+ LOGGER.warn("sax error", exception);
+ }
+
+ @Override
+ public void fatalError(final SAXParseException exception)
+ throws SAXException {
+ LOGGER.warn("sax error", exception);
+ }...
[truncated message content] |