Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

lazy initialization of block rank table. this causes that the table is not initialized when there is no search is done. the effect is most strong if YaCy is started headless which causes no browser pop-up which otherwise would load the search page and therefore trigger the initialization of the table.

Michael Peter Christena61f44f9e442
diff --git a/htroot/yacyinteractive.java b/htroot/yacyinteractive.java
index 959dbec48..845ca476b 100644
--- a/htroot/yacyinteractive.java
+++ b/htroot/yacyinteractive.java
@@ -27,6 +27,7 @@
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.search.Switchboard;
import net.yacy.search.SwitchboardConstants;
+import net.yacy.search.ranking.BlockRank;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
@@ -37,6 +38,8 @@ public class yacyinteractive {
public static serverObjects respond(final RequestHeader header, serverObjects post, final serverSwitch env) {
final Switchboard sb = (Switchboard) env;
final serverObjects prop = new serverObjects();
+ BlockRank.ensureLoaded();
+
prop.put("topmenu", sb.getConfigBool("publicTopmenu", true) ? 1 : 0);
final String promoteSearchPageGreeting =
(env.getConfigBool(SwitchboardConstants.GREETING_NETWORK_NAME, false)) ?
diff --git a/htroot/yacysearch.java b/htroot/yacysearch.java
index 182030eea..31fe9d53a 100644
--- a/htroot/yacysearch.java
+++ b/htroot/yacysearch.java
@@ -78,6 +78,7 @@ import net.yacy.search.query.AccessTracker;
import net.yacy.search.query.QueryParams;
import net.yacy.search.query.SearchEvent;
import net.yacy.search.query.SearchEventCache;
+import net.yacy.search.ranking.BlockRank;
import net.yacy.search.ranking.RankingProfile;
import de.anomic.data.DidYouMean;
import de.anomic.data.UserDB;
@@ -96,6 +97,7 @@ public class yacysearch {
final Switchboard sb = (Switchboard) env;
sb.localSearchLastAccess = System.currentTimeMillis();
+ BlockRank.ensureLoaded();
final boolean searchAllowed =
sb.getConfigBool("publicSearchpage", true) || sb.verifyAuthentication(header);
diff --git a/htroot/yacysearch_location.java b/htroot/yacysearch_location.java
index 68b3ac080..2a4c1cbf4 100644
--- a/htroot/yacysearch_location.java
+++ b/htroot/yacysearch_location.java
@@ -31,6 +31,7 @@ import net.yacy.document.LibraryProvider;
import net.yacy.document.geolocalization.GeoLocation;
import net.yacy.search.Switchboard;
import net.yacy.search.SwitchboardConstants;
+import net.yacy.search.ranking.BlockRank;
import de.anomic.server.serverCore;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
@@ -40,7 +41,8 @@ public class yacysearch_location {
public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
final Switchboard sb = (Switchboard) env;
final serverObjects prop = new serverObjects();
-
+ BlockRank.ensureLoaded();
+
prop.put("kml", 0);
if (header.get(HeaderFramework.CONNECTION_PROP_EXT, "").equals("kml") ||
diff --git a/source/net/yacy/search/ranking/BlockRank.java b/source/net/yacy/search/ranking/BlockRank.java
index 24b146e22..4e4abeafc 100644
--- a/source/net/yacy/search/ranking/BlockRank.java
+++ b/source/net/yacy/search/ranking/BlockRank.java
@@ -56,7 +56,8 @@ import net.yacy.search.index.Segment;
public class BlockRank {
public static BinSearch[] ybrTables = null; // block-rank tables
-
+ private static File rankingPath;
+ private static int count;
/**
* collect host index information from other peers. All peers in the seed database are asked
@@ -214,6 +215,7 @@ public class BlockRank {
byte[] hosth = new byte[6];
String hosths, hostn;
HostStat hs;
+ ensureLoaded();
for (int ybr = 0; ybr < ybrTables.length; ybr++) {
row: for (int i = 0; i < ybrTables[ybr].size(); i++) {
hosth = ybrTables[ybr].get(i, hosth);
@@ -240,11 +242,18 @@ public class BlockRank {
* @param rankingPath
* @param count
*/
- public static void loadBlockRankTable(final File rankingPath, final int count) {
- if (!rankingPath.exists()) return;
+ public static void loadBlockRankTable(final File rankingPath0, final int count0) {
+ // lazy initialization to save memory during startup phase
+ rankingPath = rankingPath0;
+ count = count0;
+ }
+
+ public static void ensureLoaded() {
+ if (ybrTables != null) return;
ybrTables = new BinSearch[count];
String ybrName;
File f;
+ Log.logInfo("BlockRank", "loading block rank table from " + rankingPath.toString());
try {
for (int i = 0; i < count; i++) {
ybrName = "YBR-4-" + Digest.encodeHex(i, 2) + ".idx";
@@ -287,6 +296,7 @@ public class BlockRank {
* @return
*/
public static int ranking(final byte[] hash) {
+ ensureLoaded();
return ranking(hash, ybrTables);
}