From a05d738ea425d1f0ef156e22f96252327d2f14c5 Mon Sep 17 00:00:00 2001 From: orbiter Date: Sun, 29 May 2005 00:34:01 +0000 Subject: [PATCH] enhanced caching, removed bug causing outOfMemory git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@195 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- .../plasma/plasmaWordIndexAssortment.java | 8 ++++---- .../plasmaWordIndexAssortmentCluster.java | 19 +++++++++++++++---- .../anomic/plasma/plasmaWordIndexCache.java | 4 ++-- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/source/de/anomic/plasma/plasmaWordIndexAssortment.java b/source/de/anomic/plasma/plasmaWordIndexAssortment.java index 5f77f6243..d29b539e0 100644 --- a/source/de/anomic/plasma/plasmaWordIndexAssortment.java +++ b/source/de/anomic/plasma/plasmaWordIndexAssortment.java @@ -107,18 +107,18 @@ public final class plasmaWordIndexAssortment { // open existing singeton tree file try { assortments = new kelondroTree(assortmentFile, bufferSize); - log.logSystem("Opened Assortment Database, " + assortments.size() + " entries, width " + assortmentCapacity); + if (log != null) log.logSystem("Opened Assortment Database, " + assortments.size() + " entries, width " + assortmentCapacity + ", " + bufferkb + "kb buffer"); } catch (IOException e){ - log.logError("unable to open assortment database: " + e.getMessage()); + if (log != null) log.logError("unable to open assortment database: " + e.getMessage()); e.printStackTrace(); } } else { // create new sigleton tree file try { assortments = new kelondroTree(assortmentFile, bufferSize, bufferStructure(assortmentCapacity)); - log.logSystem("Created new Assortment Database, width " + assortmentCapacity); + if (log != null) log.logSystem("Created new Assortment Database, width " + assortmentCapacity + ", " + bufferkb + "kb buffer"); } catch (IOException e){ - log.logError("unable to create assortment database: " + e.getMessage()); + if (log != null) log.logError("unable to create assortment database: " + e.getMessage()); e.printStackTrace(); } } diff --git a/source/de/anomic/plasma/plasmaWordIndexAssortmentCluster.java b/source/de/anomic/plasma/plasmaWordIndexAssortmentCluster.java index 0d640bebd..444fa7c90 100644 --- a/source/de/anomic/plasma/plasmaWordIndexAssortmentCluster.java +++ b/source/de/anomic/plasma/plasmaWordIndexAssortmentCluster.java @@ -58,19 +58,30 @@ public final class plasmaWordIndexAssortmentCluster { private int clusterCapacity; private serverLog log; private plasmaWordIndexAssortment[] assortments; - private long completeBufferSize; + private long completeBufferKB; public plasmaWordIndexAssortmentCluster(File assortmentsPath, int clusterCapacity, int bufferkb, serverLog log) { // set class variables if (!(assortmentsPath.exists())) assortmentsPath.mkdirs(); this.clusterCapacity = clusterCapacity; - this.completeBufferSize = bufferkb * 1024; + this.completeBufferKB = bufferkb; this.log = log; this.assortments = new plasmaWordIndexAssortment[clusterCapacity]; - // initialize cluster + // open cluster and close it directly again to detect the element sizes + int[] sizes = new int[clusterCapacity]; + int sumSizes = 1; + plasmaWordIndexAssortment testAssortment; + for (int i = 0; i < clusterCapacity; i++) { + testAssortment = new plasmaWordIndexAssortment(assortmentsPath, i + 1, 0, null); + sizes[i] = testAssortment.size() + clusterCapacity - i; + sumSizes += sizes[i]; + testAssortment.close(); + } + + // initialize cluster using the cluster elements size for optimal buffer size for (int i = 0; i < clusterCapacity; i++) { - assortments[i] = new plasmaWordIndexAssortment(assortmentsPath, i + 1, (int) completeBufferSize / clusterCapacity, log); + assortments[i] = new plasmaWordIndexAssortment(assortmentsPath, i + 1, (int) completeBufferKB * sizes[i] / sumSizes, log); } } diff --git a/source/de/anomic/plasma/plasmaWordIndexCache.java b/source/de/anomic/plasma/plasmaWordIndexCache.java index 8e9792212..f22df0a7e 100644 --- a/source/de/anomic/plasma/plasmaWordIndexCache.java +++ b/source/de/anomic/plasma/plasmaWordIndexCache.java @@ -56,8 +56,8 @@ public final class plasmaWordIndexCache implements plasmaWordIndexInterface { private static final String oldSingletonFileName = "indexSingletons0.db"; private static final String newSingletonFileName = "indexAssortment001.db"; private static final String indexAssortmentClusterPath = "ACLUSTER"; - private static final int assortmentLimit = 20; - private static final int ramcacheLimit = 60; + private static final int assortmentLimit = 50; + private static final int ramcacheLimit = 70; // class variables